Re: [Tutor] split or replace

2009-06-05 Thread W W
On Fri, Jun 5, 2009 at 6:18 AM, Norman Khine nor...@khine.net wrote:

 Hello,
 What is the way to group each value so that I get a list, from a string
 like:

 dir = '/expert/forum/expert/expert'
 list = ['/expert', '/forum', '/expert', '/expert']

 I've tried:
  dir = '/expert/forum'
  dir.split('/')
 ['', 'expert', 'forum']
  dir.replace(/expert,)
 '/forum'
  dir = '/expert/forum/expert'
  dir.replace(/expert,)
 '/forum'


will it always begin with /? and is there any reason you want to retain the
/? because this gets them without the /
 dir.split('/')[1:]
['expert', 'forum', 'expert', 'expert']

I think you might be able to use a list comprehension. Otherwise you could
do this:
 dir.replace('/',' /').split()
['/expert', '/forum', '/expert', '/expert']

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


Re: [Tutor] serious problem with graphics module

2009-06-04 Thread W W
On Thu, Jun 4, 2009 at 7:47 PM, Kent Johnson ken...@tds.net wrote:

 On Wed, Jun 3, 2009 at 5:51 PM, W Wsri...@gmail.com wrote:

  Do you (or sombody else) know how to get ipython working with Python 2.6
  (you know,
  the Python release, which has that new turtle module ;-)   )
 
  doesn't install on my Windows box... other than that I've got no
 experience
  with it

 What trouble did you have? I use IPython with Python 2.6 on Windows.
 Not sure how I installed it though.


After install it gave me this:

*** run_installscript: internal error 0x ***

same error I get trying to install pyreadline. No shortcuts on the
desktop/start menu/etc show up. All the files are in the site-packages
directory, it seems.
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] serious problem with graphics module

2009-06-03 Thread W W
Forwarding on to the list...

-- Forwarded message --
From: Gregor Lingl gregor.li...@aon.at
Date: Wed, Jun 3, 2009 at 3:46 PM
Subject: Re: [Tutor] serious problem with graphics module
To: W W sri...@gmail.com




W W schrieb:

 On Tue, Jun 2, 2009 at 7:12 PM, Gregor Lingl gregor.li...@aon.at mailto:
 gregor.li...@aon.at wrote:

snip
Does anyone have experience with using IPython with Tkinter?


 Plenty, and it works wonderfully. I've never had any errors (that I know
 of) that weren't of my own making ;)

Do you (or sombody else) know how to get ipython working with Python 2.6
(you know,
the Python release, which has that new turtle module ;-)   )

doesn't install on my Windows box... other than that I've got no experience
with it
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Spell checking source code?

2009-06-02 Thread W W
On Tue, Jun 2, 2009 at 3:15 AM, ALAN GAULD alan.ga...@btinternet.comwrote:


  From: wormina...@gmail.com wormina...@gmail.com
  To: Alan Gauld alan.ga...@btinternet.com
  Sent: Tuesday, 2 June, 2009 1:09:39 AM
  Subject: Re: [Tutor] Spell checking source code?
 
  In vim,
 
  :set spell
  :set nospell
  :help spell


 But that will check the whole file. The OP only wanted to spell
 check the comments. Unless I'm missing something?


Shouldn't be too difficult to write a vim script to check only # to EOL, '
to ',  to , ''' to ''' and  to . I think that's the only non-code
available?
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How o convert spaces into tabs??

2009-06-02 Thread W W
On Tue, Jun 2, 2009 at 12:42 PM, jyotsna guleria
jyotsna.gule...@gmail.comwrote:


 Hello every one,

 I am trying to parse a file:

 I want to convert all the spaces in between the characters to single tab.

 e.g: my file has contents like:

 1G579011  10  2   0  00
 0   0   00
 5Ht-2  60459  11  0   0  00
 0   0   00


 I want them to be separated by a single tab not with spaces..

 It should look like:

 1G5790111020000000
 5Ht-2604591100000000

 each separated by Tab...

 It is a text file containing such a data ..


Easiest way I know of goes something like this:

for line in myfile:
   newline = '\t'.join(line.split())

Consider:

In [16]: x = 'the quick brownfox   ate   some   spam and eggs'

In [17]: x.split()
Out[17]: ['the', 'quick', 'brown', 'fox', 'ate', 'some', 'spam', 'and',
'eggs']

In [18]: '\t'.join(x.split())
Out[18]: 'the\tquick\tbrown\tfox\tate\tsome\tspam\tand\teggs'

In [19]: print '\t'.join(x.split())
the quick   brown   fox ate somespamand eggs


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


Re: [Tutor] python workspace

2009-06-02 Thread W W
On Tue, Jun 2, 2009 at 1:30 PM, Dave Angel da...@ieee.org wrote:

 roberto  wrote:

  On Tue, Jun 2, 2009 at 10:54 AM, roberto robert...@gmail.com wrote:


 
  hello,
  i'd like to ask if there is anything in python which helps to see what
  variables have been defined and their type and their dimension etc;
 
  if any of you has ever used Matlab, i mean something really similar to
  its workspace, where all the user created variables are stored and
  constantly updated
 
  thank you
  --
  roberto



 You could use the commercial Komodo IDE.  It's got a debugger that runs the
 Python code as a separate process, so it can be used for GUI debugging as
 well as console work.  I use it with wxPython, and Python 2.6.2

 http://www.activestate.com/komodo/


Wingware also has a commercial IDE, and most of the functionality is
included in the free student/personal use version. They were also generous
enough to donate I think it was 4 or 8 commercial licensees to our
PyArkansas un-conference. I played around with it a bit and it seemed like
quite a solid IDE.

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


Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread W W
On Mon, Jun 1, 2009 at 2:27 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 Kent Johnson ken...@tds.net wrote

  Yesterday, I posted a question to python-list involving custom
  deepcopies in an inheritance hierarchy. I haven't received any

 ISTM that in general B.__deepcopy__() should call A.__deepcopy__() to do
 the A part of the work. In your example, this won't work because
 A.__deepcopy__() assumes that subclasses have a one-argument constructor.
 So, I would say that B is not fulfilling the contract assumed by A.


 I've been trying to think of a clear way to reply to this but kept getting
 sucked into discussions of the Liskoff Substitution Principle and Law of
 Demeter and such. Kent's explanation is much clearer!

 But this example highlights a real problem (IMHO) with dynamic OOP
 languages like Python. You can write classes that examine themselves at
 runtime and manipulate attributes that were actually
 provided by subclasses (or even by the application writer!). This makes any
 attempt at things like deepcopy fraught with difficulty because the clear
 separation of concerns between parent and subclass has been broken.

 It is very important for good OO design that classes only operate on their
 own data. But when you can dynamically add attributes to instances after
 theit creation, as you can in Python, it's almost impossible to distinguish
 between attributes of the parent class and the subclass. It's one of the
 penalties of Python's dynamic nature and there is no easy solution  to the
 general case. In the specific case you need to read the code of both parent
 and subclass and the application(s) using them!

  What if you give B a one-arg constructor by making the bTag argument
 optional? Then I think B.__deepcopy__() can call A.__deepcopy__(), then do
 the B part of the copy on the result.


 As a minimum subclasses should adhere to the parent interface.
 Unfortunately because Python only allows a single constructor that can be a
 limiting factor :-(
 ( Multiple constructors (or factory methods) is one feature I  would like
 to see added to Python! )


Wouldn't it be possible to create sort of a... bastardization? i.e.

def __init__(self, *args):
if len(args) == 0:
#do something
if len(args) == 1:
   #do something else

etc.?

Or would that create more problems than is worth it?

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


Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread W W
On Mon, Jun 1, 2009 at 8:59 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 W W sri...@gmail.com wrote

  ( Multiple constructors (or factory methods) is one feature I  would like
 to see added to Python! )


 Wouldn't it be possible to create sort of a... bastardization? i.e.

 def __init__(self, *args):
   if len(args) == 0:
   #do something
   if len(args) == 1:
  #do something else

 Or would that create more problems than is worth it?


 Thats the standard workaround but its not clean and certainly
 not self documenting. Its also not reliable becaause thre is nothing
 to stop someone calling it with the first argument of the 2 arg case
 (a filename maybe?) and then it gets treated as a single arg case
 ( a tuple of values say?) Oops!

 Whereas in C++/Java style you could say

 class C:
   @constructor
   def C(fname, count);...

   @constructor
   def C(valueTuple):

 etc.

 Or in Delphi style:

 class C:
@constructor
def LoadFromFile(fname, count): ...
@constructor
def Create(valueTuple):...

 Personally I prefer the Delphi style sincve it makes the constructor
 call explicit and adds to the documentation.

 Alan G


That does make it problematic... although I suppose checking the type would
be a workaround - still, not simple or beautiful. Has this been introduced
as a PEP?

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


Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread W W
On Mon, Jun 1, 2009 at 3:55 PM, Alan Gauld alan.ga...@btinternet.comwrote:


 W W sri...@gmail.com wrote

 class C:
   @constructor
   def LoadFromFile(fname, count): ...
   @constructor
   def Create(valueTuple):...

 Personally I prefer the Delphi style sincve it makes the constructor
 call explicit and adds to the documentation.

 Alan G


 That does make it problematic... although I suppose checking the type
 would
 be a workaround - still, not simple or beautiful. Has this been introduced
 as a PEP?


 Type checking is the problem. Until Python can distinguish methods based
 on types (which introduces other issues)  thisi is difficult with the
 C/Java style.

 We can fake the Delphi style by using a default constructor and then just
 calling the constructors after initialisation:

 class C:
def __init__(): pass
   @constructor
   def LoadFromFile(fname, count): ...
  @constructor
  def Create(valueTuple):...

 c = C()
 c.LoadFromFile(fn, cnt)

 But its two lines not one... :-(

 And so far as I know it has not been PEPd although I'm sure it has
 been discussed.


I'm not sure how types are implemented in the underlying C, but it seems
that it should be a somewhat trivial addition. I mean, type checking is
already built-in to python, i.e. type('a')  o/p: type 'str', so just
building a handler specific to the __init__ method, or modifying it if it's
already unique, should be able to take care of it.

I guess one way you could try to parse it on your own is build a list of
types: f1 = [type(''), type(1), type(())], f2 = [type([]), type(1)]]  and
compare the types of arguments provided from *args. I suppose really, one
could go so far as to build a dict of lists with the lengths:

spam = {1:[[type(''))],], 2:[[type([]), type(())], [type(1), type(1.0)]

then compare then lengths of args first.

That's a lot of work, though :P
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class Tips

2009-05-30 Thread W W
On Sat, May 30, 2009 at 8:20 PM, David da...@abbottdavid.com wrote:

 Alan Gauld wrote:

 David da...@abbottdavid.com wrote

 I took this program that determines a fertilizer application rate;
 ...
 And converted it to class/object to learn how they work. Just looking
for some pointers, if I did it correctly etc.

 snip

One thing that's probably not in the scope of the program but really usually
a good idea is error checking.
i.e.  this line:
rate = float(raw_input(Enter rate i.e. (0.5) : ))

could be converted to something like:
try:
rate = float(raw_input(Enter rate...))
except ValueError:
print Invalid input
#Quit or loop until valid input is entered.

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


Re: [Tutor] Docking Windows using Python

2009-05-29 Thread W W
On Fri, May 29, 2009 at 7:48 PM, Hi haztan...@gmail.com wrote:

 My program will have two windows. I want to be able to dock the two so they
 are side by side. I am wondering if this is doable in Python. If so, could
 someone lead me to the right direction on where to look? Thank you very
 much.


I think you could really use any GUI - it really all depends on how you want
to do it. I'm not 100% sure about having two windows with Tkinter. But you
could fairly easily (I think) hide copies of widgets inside the main window
and show them only after the second window is docked, then hide that window.

There are probably plenty of other ways to do it, that's just the first that
popped into my mind with my limited knowledge.

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


Re: [Tutor] Tinkering with Tkinter

2009-05-26 Thread W W
On Mon, May 25, 2009 at 7:45 PM, Doug Reid rnrcr...@yahoo.com wrote:

  The following code and it's explanation doesn't seem to work:


 1.  from Tkinter import *

 2.  tk = Tk()

 3.  btn = Button(tk, text=click me)

 4.  btn.pack()



 In line 1, we import the contents of the
 Tk module, so we can use them—the

 most useful of these is
 Tk, which creates a basic window to which we can then add

 things. After you type in line 2, that window will suddenly appear on the
 screen.

 In line 3, we create a new Button and assign it to the variable
 btn. The button

 is created by passing the
 tk object as a parameter, along with a named parameter with the words
 ‘click me’.

 Nothing appears on the screen after I enter line 2...I can type in the code
 in the editor and double click after saving the file and it does, but not
 from the shell, how can that be fixed or am I doing something wrong?


Works for me!

What is your os/python verision? Are you working from Idle? AFAIK, IDLE is
written in Tk and so it does not so much like Tkinter programs in it's
interactive shell. If you're on windows, try typing cmd in the run dialog
and then type python at the prompt, then try the example.

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


Re: [Tutor] IP-range

2009-05-25 Thread W W
On Sun, May 24, 2009 at 10:18 PM, Paras K. para...@gmail.com wrote:

 Hello,

 I came across your answer / assistance on the IP range. I am fairly new to
 the python world of programming. However, up to this point I have always
 been able to get my programs to work by reading the books or following the
 guides I find through google.com

 Here is what I have to do:

 I have to read a number of cvs files into 1 large file. (I have been able
 to get that done through a perl script). But after I get it into a large cvs
 file, I need to be able to look at each row and see if it falls within a
 specific IP ranges.

 IP Ranges:

 162.x.x.x
 151.130.x.x
 145.x.x.x

 These are just some examples of the IP ranges.

 The csv file has data like below:




   63.145.40.32 Gnutella File Search 14 5/15/2009 0:48  151.40.133.25 Gnutella
 File Search 14 5/14/2009 16:21  145.133.19.147 BitTorrent Client Activity
 13 5/14/2009 19:20

snip


You know, unless you have an ulterior reason for merging all the files, you
could probably just read each of them with a loop in python. Or use python
to build the main file - which would eliminate your need for that error
check.

Assuming that the first element in the line will always be the IP, this
should help:

In [12]: myline = '192.168.1.1 Gnutella File Search 24 5/15/2009 0:48'

In [15]: ip = myline.split(' ')[0]

In [16]: split_ip = ip.split('.')

In [17]: split_ip
Out[17]: ['192', '168', '1', '1']

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


Re: [Tutor] Find a good linux distribution with python.

2009-05-25 Thread W W
On Mon, May 25, 2009 at 3:57 AM, Michael Bernhard Arp Sørensen 
mich...@arpsorensen.dk wrote:

 snip
 I just wished that Python was upgraded in the distros. If I want to play
 with Python3, I will need to compile it my self and specify which Python
 interpretor to use in each Python file. But this is a small problem. snip


In Ubuntu Jaunty(?)- 8.11 I believe- you can apt-get the python3 package (or
whatever you use). I think there's also a python 2.6 package and the default
is python 2.5.

I'm assuming you use terminal, and if so you can setup aliases in your
.bashrc to go into whatever mode you want. Just add these lines to your
.bashrc

alias pymode3='alias python=python3'
alias pymode1.6='alias python=python1.6'

I forget if/how to change ipython between versions of python though. You'd
just have to put similar aliases in your bash file.

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


Re: [Tutor] Hi everyone

2009-05-21 Thread W W
On Thu, May 21, 2009 at 2:42 AM, spir denis.s...@free.fr wrote:

 snip
while word:
 position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]


Something that many of us use for debugging, and is also useful for
comprehension is a simple print statement. If you were to convert the loop
to this:

while word:
position = random.randrange(len(word))
   jumble += word[position]
   word = word[:position] + word[(position + 1):]
   print jumble
   print word
   # Optional - for further understanding
   print word[:position]
   print word[(position+1):]

you would basically see what Denis wrote - only every step through the loop.

HTH,
Wayne

p.s. - When you start graphical programming, I'd look at pyglet or pygame.
Although to really understand event driven programming, it really helped me
to start writing programs with Tkinter. YMMV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing Bible verses

2009-05-21 Thread W W
On Thu, May 21, 2009 at 4:26 PM, Eduardo Vieira eduardo.su...@gmail.comwrote:

 Hello, I'm planning to create a script to read a certain file, find
 the line that contains Bible references and then use that to query a
 bible database in order to print the verses in another file.
 I will be looking for lines like these:
 Lesson Text: Acts 5:15-20, 25; 10:12; John 3:16; Psalm 23

 So, references in different chapters are separated by a semicolon. My
 main challenge would be make the program guess that 10:12 refers to
 the previous book. 15-20 means verses 15 thru 20 inclusive. I'm afraid
 that will take more than Regex and I never studied anything about
 parser tools, really.

 Any suggestion how I should approach this?


Actually, a regex probably wouldn't be too far off. If you're comfortable
working with them it may even be a good thing...
Will the line always begin with Lesson text:? If so, that makes it a lot
easier. Something like:

for line in file:
if line starts with Lesson text:
skip lesson text
book = first word(s)
verse[book] = list of references

that's a really basic flow of logic, but it's probably how I'd do it.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Triggering code on 1 minute intervale ..

2009-05-09 Thread W W
On Sat, May 9, 2009 at 3:26 PM, Alex Feddor alex.fed...@gmail.com wrote:

 .. What will be the best solution to trigger python code every minute as
 soon as PC in on.

an autorun script... and in your script use the time.sleep(60) I believe.

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


Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread W W
On Tue, May 5, 2009 at 5:41 AM, spir denis.s...@free.fr wrote:

 Le Tue, 5 May 2009 00:41:39 +0100,
 Alan Gauld alan.ga...@btinternet.com s'exprima ainsi:

   Backwards compatibility.  The file type was introduced in python 2.2,
   before which there was open.
 
  And file has been removed again in Python v3
  In fact open is now an alias for io.open and no longer simply returns
  a file object - in fact the file type itself is gone too!
 
  A pity, there are cases where I found file() more intuitive than
  open and vice versa so liked having both available. The fact that it
  looked like creating an instance of a class seemed to fit well
  in OO code.

 Same for me. It makes files an exception in the python OO system.
 Conversely, I have always considered open(), rather than file(), a flaw.
 (But there are numerous things on which I have a different point of view
 than the majority of pythonistas ;-)


Well, when you consider that it's really, underneath everything(way down in
the assembly code), a pointer to a location on the hard disk/memory, open
does make a little more sense. Of course, conversely there are also (like
Alan mentioned) cases where file just makes more sense when you're looking
at/writing the code, even if the concept may not technically be correct.
Still, I think that's part of OO programming - obscuring some of the
underlying ideas in favor of clarity of purpose.

For those of us who may still find a need/desire to use file(), I'm sure
file = open still works in python3 ( of course that's not making one
preferably obvious right way of doing things )

-Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] output formatting

2009-04-25 Thread W W
On Fri, Apr 24, 2009 at 10:57 PM, Matt Domeier dome...@umich.edu wrote:

 Hello,

 I have a series of lists that I need to output into files with a specific
 format. Specifically, I need to have line breaks after each entry of the
 list, and I need to do away with the ['..'] that accompany the data after I
 transform the list into a string. Can I simply append a '\n' to the end of
 all the list entries in order to enact line breaks?


Is this what you're looking for?

In [3]: print '\n'.join(['the quick brown fox', 'jumps over', 'the lazy
dog'])
the quick brown fox
jumps over
the lazy dog

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


Re: [Tutor] understanding urllib.urlopen

2009-04-23 Thread W W
On Thu, Apr 23, 2009 at 10:58 AM, johnf jfabi...@yolo.com wrote:

 On Thursday 23 April 2009 08:44:07 am Emile van Sebille wrote:
  johnf wrote:
  snip
 
   But if I attempt this
   urllib.urlopen( 
   http://maps.google.com?q='18http://maps.google.com?q=%2718Tadlock 
   Place Woodland CA'
   ) it always fails.
 
  What do you get?  I don't get an error.
 
  Emile
 
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor

 OK - I'm also getting something when I use the command line.  Must be the
 code
 I have.  Thanks


I don't know about maps, but I know the normal google search doesn't like to
be scraped.

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


Re: [Tutor] Python help

2009-04-22 Thread W W
On Wed, Apr 22, 2009 at 11:08 AM, IT_ForMe snice14...@aol.com wrote:


 Anyone know how to program this using Python

 Add up the prices for items in a shopping cart. Some items are taxable and
 some items are not. You may assume a 7% tax rate for all taxable items.
 Apply a 10% discount if the customer is a student. (hint, instead of asking
 the user to input items, set them up as an associative array in the code)


My guess is most of us could do it, and this is homework.

We have a policy against that sort of thing, but if you'd like to give it a
try and then ask for help if you get stuck, we're more than willing to help.

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


Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 8:48 AM, Matt
hellzfury+pyt...@gmail.comhellzfury%2bpyt...@gmail.com
 wrote:

 Hey everyone,

 First post to this list. I hope I'm doing it right.

 Let's say I want to run func 10 times Is there a more pythonic way to do it
 than this:
 for i in xrange(10):
  func()


AFAIK that's the most pythonic way to do it... and probably how I'd do it...
if I had a function I needed to run 10 times :P

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


Re: [Tutor] Looping

2009-04-20 Thread W W
On Mon, Apr 20, 2009 at 12:34 PM, Matt
hellzfury+pyt...@gmail.comhellzfury%2bpyt...@gmail.com
 wrote:

 Thank you. Func is in fact a call to an external non-python program. =]
 Therefore, the loop must actually be mindlessly done. My question, however,
 has been answered.
 As an aside, why use range rather than xrange? I was under the impression
 that xrange is a generator and therefore more memory efficient.


Probably because for small values (under 100), range just looks cleaner, and
as far as memory goes it's not a whole lot of difference.

AFAIK,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] for loop

2009-04-16 Thread W W
On Thu, Apr 16, 2009 at 3:45 PM, mbikinyi brat mbikinyi_b...@yahoo.comwrote:

 Dear ALL,
 I am a beginner in python and I just copied the code in blue below and
 execute and had the result in green. Then I thought *letter* should be a
 special word in python. Then I now replace letter whith *chic*  and yet
 the same results is obtained. I cannot reconcile them. Can someone explained
 to me please?


I think your confusion lies in how python for loops work.

Python in this case is a string. You could replace it with Spam
Knights or Ni, if you so desire. A string is an iterable - in other
words, you can iterate over it automatically.

With a language like C++ you would write something like this:

string foo = python;
for(int x = 0; x  foo.size; x++){
cout  foo.at(x)  endl;
}

to iterate over the string. Python takes care of that for you with any
iterable type (list, set, etc.)

for item in [1, 2, 3]:
print item

for letter in word:
print word

for foobar in (1, 0, 234, 'hello', 'foo'):
print foobar

It all works the same. It's rather useful :)

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


Re: [Tutor] Looking for starter projects

2009-04-15 Thread W W
On Wed, Apr 15, 2009 at 3:50 AM, Evert Edel beat...@gmail.com wrote:

 Hi all,
 snip
 Now since I've got the learning python book I first did a quick read trough
 it and now I'm going more slowly trough it and doing all the explained
 things (in the interactive prompt). I do understand the basics behind OOP
 and I'm wanting to start some smaller projects using the book as a reference
 to get my hands on python. It seems to me that it's better to learn it with
 smaller projects (and evolving with those).


That's probably a fairly good idea... I would guess that most of us learned
the same way, or at least in similar ways.



 But I really don't know what smaller projects would be good to start on as
 beginner. I've got some ideas but those are more advanced (making a mpd
 client, some website ideas).

 I hope you can give me some starting projects to learn python :).


Well, what do you enjoy? That's really probably the best way to program -
when you program things you enjoy you tend to be more likely to stick with
it.

Do you like games? Maybe you could program a tic-tac-toe game. Or a guessing
game. Do you like math? Perhaps you could write programs that will do
certain math functions for you (Like the Fibonacci series, computing area,
maybe even doing some calculus).

Do you like drawing pictures? If you use Tkinter or the turtle module you
could write some programs to do that. Maybe you could try writing your name,
first in block, then in script (actually the script would end out rather
complicated, but certainly fun[if that's what you enjoy]!)

 And of course, if you get stuck anywhere and need some help, we're always
willing to help point you in the right direction.

Good luck!
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python books

2009-04-15 Thread W W
On Wed, Apr 15, 2009 at 4:45 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

 It's unlikely you are going to find a pdf on Python that's suitable for
 beginners. Do you mean pdf or a digital book? There are Python books in
 digital form on the web. I'm not quite sure how it works, but I know of at
 least one public library has them. I think it works that if you have a
 library card, then you can get web access to read the book on-line. I think
 this operates at a college level too. snip


Snake Wrangling for Kids is a perfectly good pdf for beginners (both to
programming and python). I'd say the same about Think like a computer
scientist - http://www.greenteapress.com/thinkpython/thinkpython.html

But maybe that's just me :P
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Here's something to talk about (Weidner, Ronald)

2009-04-15 Thread W W
On Wed, Apr 15, 2009 at 12:27 PM, Carnell, James E 
jecarn...@saintfrancis.com wrote:

 Since # the list seems thick with OOP questions at the moment, I thought
 this might # be relevant.  Digest and enjoy.

 class Item ( object ):

def __init__( self ):
self._FullName = ''
self._Recovery = 0
self._Exporter = SimpleItemExporter (); # ? Don't
 understand

 Bummer, I was hoping to consider myself at the tip of intermediate
 python programming sigh...

 This is the first time I have ever seen a variable set to what appears
 to be a function address(?). Since I am at work I can't copy paste this
 thing yet. Is SimpleItemExporter from the parent class, object? I am
 assuming Item extends or inherits (or whatever the right word is) from
 object.


First off, the semicolon is probably a syntax error.

SimpleItemExporter is probably a class, but I don't think object is the
parent. If you were trying to access something from object I'm fairly
certain you'd use the dot operator, so it would be
object.SimpleItemExporter()

But if it's a class it would be a new instance of that class. Otherwise it
doesn't make a lot of sense to have the parenthesis (unless
SimpleItemExporter returns something useful... which it isn't named like it
should).

Consider the following:
In [1]: def foo():
   ...: print Hello
   ...:
   ...:

In [2]: x = foo()
Hello

In [3]: x

In [4]: x('a')
---
TypeError Traceback (most recent call last)

/home/wayne/ipython console in module()

TypeError: 'NoneType' object is not callable



In [5]: class foo:
   ...: def __init__(self, spam):
   ...: print spam
   ...:
   ...:

In [7]: x = foo('eggs')
eggs

In [8]: x
Out[8]: __main__.foo instance at 0x9f0304c

In [9]: x()
---
AttributeErrorTraceback (most recent call last)

/home/wayne/ipython console in module()

AttributeError: foo instance has no __call__ method

In [10]: x.__init__('eggs')
eggs



--and---

In [11]: class spam:
   : def __init__(self, eggs):
   : lay(eggs)
   : def lay(x):
   : print x
   :
   :

In [13]: class foo(spam):
   : def __init__(self, bar):
   : lay(bar)
   :
   :

In [14]: x = foo('Ni')
---
NameError Traceback (most recent call last)

/home/wayne/ipython console in module()

/home/wayne/ipython console in __init__(self, bar)

NameError: global name 'lay' is not defined


-
The above snippets seem to show what I stated before - SimpleItemExporter is
a class on it's own - not a method/function in the object class. If that
were the case then my class foo should have direct access to the lay
function, AFAIK.

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


Re: [Tutor] Event Handling--Key Press, Mouse Movement ...

2009-04-13 Thread W W
On Mon, Apr 13, 2009 at 1:22 PM, Gregor Lingl gregor.li...@aon.at wrote:

 Wayne Watson schrieb:

 Sometime ago, one of my posts brought a response brief exchange on event
 handling*. Where might I find more about event handling with respect to the
 keyboard, and particularly with a mouse. In the latter case, I'm interested
 in finding the pixel position of the mouse on a canvas.snip


Easiest way:

from Tkinter import *

root = Tk()
c = Canvas(root, width = 100, height = 100)

def clicked(event):
print Clicked at x: %d y: %d % (event.x, event.y)

c.bind(Button-1, clicked)
root.mainloop()

and fire that up. There's also some motion events but I'd have to look them
up to recall.

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


Re: [Tutor] Left Alignment -- Tkinter

2009-04-02 Thread W W
On Wed, Apr 1, 2009 at 11:20 PM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Alan, the game changed in the thread you branched away from to other
 considerations. As stated there, I've thrown in the towel, but first let me
 say what the game was about. Here's the simplest example. Say I have four
 labels: small, big, house, cat, tree, and I want to put them in a column
 with full left justification. That is, like this:

 small
 big
 house
 cat
 tree

 What I get is:
  small
big
  house
eat
   tree

 More or less centered. There seems to be no way to make left justify
 happen. Once an entry is placed to the right of these items, and another
 label+entry to the right of them, it gets weird.snip


Did you get my discovery about anchor + width?

 Actually, it turns out to be my mistake at not clearly reading the
documentation he has for the
 justify option. Justify is for multiple lines of text, anchor will
anchor the text. Try with width=30,
 anchor=W and you should see what you're looking for.

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


Re: [Tutor] Left Alignment -- Tkinter

2009-03-30 Thread W W
On Sun, Mar 29, 2009 at 9:30 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

 snipI'm looking at the NM Tech Tkinter ref, pages 5-6, on the grid
 method. See pages 84-88 of Lundh. Nothing. It does not show that method.
 Search of the pdf doc shows nothing. Are these sources too old? effbot does
 have it. Yes, it's pretty decent. I've used it before. It looks like it may
 be the newest, 2005, of the three, although NM Tech seems to get updated
 pretty often. 5/2007, but I think there was a recent update. Maybe they
 don't want the students to use it.


I haven't really looked at a lot of tkinter refs. Effbot tends to have most
of the info I need - it just takes a little playing around and sometimes
google or the python list to figure out what part I'm missing.


 snip
 What I've discovered is that I did not really understand the role of
 sticky, and the bounds of the label. I thought sticky=W  meant put the
 blasted label to the left margin. What sticky means, according to Grayson's
 chapter 5 on the web, is that it allows the widget to stretch when the
 larger window is resized.  Knowing the boundaries with color coding can help
 understand that, and other oddities. Label seems to always center the text.
 Changing the label's width and height achieves interesting insights. I tried
 anchor with Label and it does interesting things. The length of the text
 messes with matters.


 http://effbot.org/tkinterbook/label.htm

 The justify option will change the alignment of text in the label.

 It didn't move the text in the label at all. There's got to be some padding
 on either end I'm missing.


Actually, it turns out to be my mistake at not clearly reading the
documentation he has for the justify option. Justify is for multiple lines
of text, anchor will anchor the text. Try with width=30, anchor=W and you
should see what you're looking for.


 Interestingly, I had set the width of the label to 12, and the color
 version showed gray to the left and right of the text, with the text in the
 center. I removed width, and the left-right spaces disappeared, but the text
 was still centered. Well, OK, the selected width, which matches the length
 of the text, really doesn't allow for justification. Foiled again. It seems
 like the width for the frame container for the latitude+BOX needs to be
 specified to give latitude some ability to go left. A column for latitude
 and one for BOX?  Beats me. Back to exploration after I finish this
 response. snip


 It appears you're correct - when I used anchor with padx it was ignored,
but when I changed padx to width it worked as expected. I'm not sure why it
does or doesn't, and I haven't had a lot of time for a lot of experimenting,
and now I have class so I'll just have to leave it for now.

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


Re: [Tutor] Automated function creation / outsourcing code

2009-03-29 Thread W W
On Sat, Mar 28, 2009 at 5:34 AM, Martin Klimach
beachfl...@googlemail.comwrote:

 snipIs there a python editor, that can automatically turn a selection of
 code into a function? Matching the input and return variables?
 snip


I've never heard of one. I suppose you could probably write your own using
regexes perhaps.

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


Re: [Tutor] Left Alignment -- Tkinter

2009-03-28 Thread W W
On Fri, Mar 27, 2009 at 2:46 PM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  It's very difficult to tell. I've tried it.
 fLocation=Frame(master)
 fLocation.pack(side=LEFT)
 I need to size the fLocation frame to make it big. As it is, it must be
 giving the smallest possible size.

 I tried this
 fLocation.pack(expand=YES,fill=BOTH,side=TOP)


Good news... I got it!

Here's something that's often a good idea when debugging overlapping layouts
(especially when you didn't design the parent!) - use different backgrounds!


First I tried grid_rowconfigure and grid_columnconfigure (which are
necessary if you want your widgets in grid to resize and sticky in the
expected places... at least in my experience. You call them on the parent
widget which can be displayed with .pack() ) on fCoords - the parent of your
labels. That didn't do anything, so I suspected the problem went deeper. So
I tried fCoords parent, fLocation. That didn't do anything, so I finally
went to /it's/ parent - master. By setting master.pack(expand=1, fill=BOTH)
along with some other tweaks I was able to get some behavior I think you'll
want.

I've left my background and border changes so you can get a better idea of
what I did. Feel free to play around with the colors, borders, sticky
options, and sizes of things. It'll probably help you to get a better grasp
of what's going on.

Here's my changes (also found here: http://rafb.net/p/clKroD65.html )

# Framing it
from   Tkinter import *
from   tkSimpleDialog import Dialog
import tkSimpleDialog
import tkMessageBox

class DialogPrototype(Dialog):

def body(self, master):
# Frames
master.configure(bg='white', bd=3)
master.pack(expand=1, fill=BOTH)
fLocationTitle = Frame(master, bg='green', bd=3)  # fL... f for frame
fLocationTitle.pack()
fLocation=Frame(master, bg='red', bd=3)
fLocation.pack(expand=1, fill=BOTH, anchor=W)
fCoords = Frame(fLocation, bg='blue', bd=3)  # lat/long
coords in a frame
fCoords.pack(fill=BOTH, expand=1, side=LEFT)
fCoords.grid_columnconfigure(0, weight=0)
fCoords.grid_columnconfigure(1, weight=1)
fCoords.grid_columnconfigure(2, weight=0)
fCoords.grid_columnconfigure(3, weight=1)
fCoords.grid_rowconfigure(0, weight=1, minsize=1)


self.title(Enter Site/Misc. Data)

# Latitude and Longitude

Label(fLocationTitle, text=Geographic Location).grid(row=0,column=0)
#Label(fCoords, text='Latitude:').grid(row=0, sticky=W)
self.lab=Label(fCoords, text='Latitude:', height=5)
self.lab.grid(row=0, column=0, sticky=W)
self.lat = Entry(fCoords, width=12)
self.lat.grid(row=0, column=1, sticky=W+E)

Label(fCoords, text='Longitude:').grid(row=0, column=2)
self.long = Entry(fCoords, width=12)
self.long.grid(row=0, column=3, sticky=W+E)

return

def apply(self):
print apply
print self.lat.get()
print self.long.get()

print setting
lat=1.0
long=0.0


root = Tk()
root.withdraw()
DialogPrototype(root)

HTH,
The -other- Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Left Alignment -- Tkinter

2009-03-28 Thread W W
On Sat, Mar 28, 2009 at 9:47 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Hi, that's an interesting way to look at it. Actually, I was about to
 probe the color idea myself, but needed to better understand how to achieve
 it. Where did grid_columnconfigure(3, weight=1) come from? I don't recall
 seeing that with Frame. Grid has columnconfigure. I started down that path
 once, but got waved off. Interesting about master.


It's not part of frame, it's actually part of the grid manager, but you have
to call it on the parent widget, and as such it won't get screwy when
combined with a parent that has the .pack method called on it.

 http://effbot.org/tkinterbook/grid.htm is a pretty decent reference.



 What I've discovered is that I did not really understand the role of
 sticky, and the bounds of the label. I thought sticky=W  meant put the
 blasted label to the left margin. What sticky means, according to Grayson's
 chapter 5 on the web, is that it allows the widget to stretch when the
 larger window is resized.  Knowing the boundaries with color coding can help
 understand that, and other oddities. Label seems to always center the text.
 Changing the label's width and height achieves interesting insights. I tried
 anchor with Label and it does interesting things. The length of the text
 messes with matters.


http://effbot.org/tkinterbook/label.htm

The justify option will change the alignment of text in the label.




 To put some focus on what I think is the real problem, try this. See if the
 text in labels lines up on the left if a column of Labels is create with
 these labels.

 vinegar
 pie
 latitude for x
 Snowy

 I haven't tried it yet, but would expect to get something like:

  vinegar
 pie
 latitude for x
 Snowy

 anchor with Label may move them to the left.

 In my case, I'm looking for stuff like:

 Latitude  BOXLongitude  BOX
 x  BOX  y BOX

 and not
Latitude BOX Longitude BOX
   x BOX   y BOX


Grid is a useful manager for this type of scenario. Grid is very similar to
the old HTML table. If you want to align it that way with grid, you could
easily do something that looks like this:

++---+--++
| Latitude   | Box| Longitude  | Box |
+-+--+--+---+--++
| x | BOX| y | BOX  |   |
+-+--+--+---++

Forgive the poor ascii art, but with some simple configurations like
columnspan, you can set it up to fit whatever you want (it usually helps to
draw out your design on paper).



 I want the text in the left column aligned. It doesn't really matter about
 the alignment of Longitude with y. One would think this would be a snap. I'm
 quite surprised no one seems to have considered an example along these
 lines. I guess everyone is center happy.


Using the grid manager and justify=LEFT you shouldn't have much of a problem



 I have yet to find a good source that explains Grid in a thorough way. Lots
 of piecemeal things. Many too brief. Perhaps the best thing I've found is
 Grayson's chapter 5 image editor, p86f. He has a very complex looking grid
 of buttons, combo boxes and images, but it all makes sense as to the layout.
 It took me awhile to see why he needed so many rows and columns for those 9
 (actually 10) thumbnails. It's all about what goes on in the lower right
 corner. Unfortunately, he had no need to align the text to the left
 uniformly in a column.


If you want to have the text align you have a few options - you can have
several labels in the same grid row/column, or you can line them up with
their own cells.

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


Re: [Tutor] (no subject)

2009-03-17 Thread W W
On Tue, Mar 17, 2009 at 2:16 PM, Jared White dukelx2...@gmail.com wrote:

 This is what i have so far an this is not what i want it to do
 NO this isnt homework i am trying to learn this myself

 #!/usr/bin/env python
 #
 #Author: J White
 #Python 2.5.2
 #
 howmany = int(raw_input('How many lines '))
 rhowmany = howmany
 strout = '*'
 while howmany  0:
 print strout
 strout += '*'
 howmany -= 1



try this:

mystr = h
print mystr*10

that should help.

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


[Tutor] best gui for the job?

2009-03-13 Thread W W
Hi,

What is the best gui to implement a simple paint-esque program in?

I already built a really simple one in Tkinter - but Tkinter lacks a
save functionality. I considered using the PIL to draw in the
background, but it didn't seem to have a good enough resolution. I
thought about pyGTK because I have some familiarity with that, but I
can't find any examples of saving a drawingarea.

Also, to clarify what I mean by best - I want it to be fairly simple
to implement (my non-saving sketch in a single color/size is about 100
lines), yet extensible - I'd like the ability to further enhance my
program down the road. Changing the opacity, and the possibility to
work with layers is a plus.

If anyone has tips or knows of any tutorials (I haven't really been
able to find anything suitable), please let me know.

Thanks for any suggestions,
Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] best gui for the job?

2009-03-13 Thread W W
On Fri, Mar 13, 2009 at 1:18 PM, Lie Ryan lie.1...@gmail.com wrote:
 W W wrote:
snip
 What do you mean good enough resolution?

I suppose I really meant quality - the shapes I drew with PIL were
severely aliased, but maybe I didn't do it right.

-Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyusb: get data via USB sent from mouse

2009-03-08 Thread W W
On Sat, Mar 7, 2009 at 9:35 AM, andré palma andre...@gmail.com wrote:
 Hi folks, I'm new on pyusb programming and to learn how to get data i'm
 trying  to get  data  sent  from  my mouse.
 I've download a program called usbview( http://www.kroah.com/linux/usb/ ) to
 display the device descriptors of any USB device  pluged  to my  computer.
 I made a peace of code that was supposed to get the data sent from my mouse
 but when i try to run it there is an error saying that the device is busy
  =S

I haven't used pyusb, but my guess is that because your window manager
is using the device already that it can't get a lock on it.

I've used pyserial for communicating with a USB device, but I've never
tried communication with a mouse.

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


Re: [Tutor] probelm pyhton shell doesnt open help please

2009-03-08 Thread W W
On Sun, Mar 8, 2009 at 3:32 PM, mustafa akkoc mustafa.c...@gmail.com wrote:

 it gives this message socket error

That's not terribly descriptive... what type of python shell? IDLE?
Interactive prompt? Ipython?

Certainly you don't mean this?

u...@system:~$ python
socket error
u...@system:~$

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


Re: [Tutor] print problem python

2009-03-07 Thread W W
On Sat, Mar 7, 2009 at 3:11 AM, Alan Gauld alan.ga...@btinternet.com wrote:
snip Python 3 has a lot of
 changes and most of the beginners material hasn't caught
 up yet. It will be easier to get answers to your questions if
 you stick with v2.6 and then when comfortable with that move
 to v3 aand learn about the differences.

As far as I know, Snake Wrangling For Kids has been updated... that's
the only one I know about.

-Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] animation with Tkinter canvas

2009-03-03 Thread W W
On Tue, Mar 3, 2009 at 3:05 AM, Mr Gerard Kelly
gerard.ke...@uqconnect.edu.au wrote:
 Hello, I am attempting to make a simple animation of a vibrating string using 
 Tkinter canvas.
 I haven't been able to find much information on how to do it.
 I have my data of position x on the string at time t. I can plot it
 withsnip
 root.update()

 canvas.pack()
 mainloop()


 Now I know that to get animation involves a root.update() and a 
 root.update_idletasks() somewhere but I can't figure out how to use these!

You don't have to use root.update. If you're drawing items on a canvas
you can delete them later.

34: for x in xrange(0, 10):
35: y = c.create_line(0,0, x*x, x*x)
36: time.sleep(.5)
37: c.update_idletasks() #Force redraw
38: c.delete(y)

Try those 5 lines and see if it works for you.

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


Re: [Tutor] Configuration File, Tkinter, IntVars--Manufacturing Variables

2009-03-03 Thread W W
On Tue, Mar 3, 2009 at 1:54 PM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:
snip
 BTW, the Quit function is original but doesn't kill the window when Quit is
 used. What fixes that? For more bonus points, it seems as though the try
 statement in the dialog should really bring up an Error dialog saying
 something is wrong, when an invalid entry occurs. No need to construct an
 error dialog for me, but I'd be curious how it might be handled.
snip



For the error dialog you can easily use tkMessageBox:

just import tkMessageBox and then use this:

In [2]: tkMessageBox.showerror('Some Error', 'An Error occurred!')
Out[2]: 'ok'

If you're expecting a specific error you can use

try:
#some statements
except SpecificError:
#Handle the error

In this case (at least the block I looked at) it's just printing to
the command line. You can handle it using any one of the message boxes
or creating your own.

     def Quit(self):
     self.running = False
     self.master.quit()
snip

You could also try self.master.destroy()

when I tried:

from Tkinter import *
root = Tk()
root.quit()

in an ipython session. It didn't close my root window but the destroy
method did.

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


Re: [Tutor] modular program

2009-03-01 Thread W W
On Sun, Mar 1, 2009 at 3:36 AM, Daniele d.co...@gmail.com wrote:
 Hi,
 I'd like to write a python program which can be easily extended by other
 people. Where can I find some best practices for writing modular programs?
 I thought about a txt file containing function calls that my program will
 parse and execute in order, or is it better just to execute every .py file
 in a certain module folder (I don't like this as modules could need to be
 executed in different moments)? Can any1 point me to a relatively simple
 program to look at?

Using classes is a pretty good idea. Then people can either import
daniele or from daniele import niftyClass.

You can pretty much take a look at any of the modules in your python
library directory. In the case of my linux box, that's
/usr/lib/python2.5/

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


[Tutor] Tkinter Grid, Listbox expand

2009-02-26 Thread W W
Hi,

I'm writing a Tkinter program and having severe problems with getting
my listbox to expand when I resize the window.

Here's my code so far:

  1 from Tkinter import *
  2 import os, shutil, tkFileDialog, tkMessageBox
  3
  4 class TkSync:
  5 def __init__(self, root):
  6 self.sbox = Listbox(root)
  7 self.sbox.grid(row=0, column=0, sticky=N+S+E+W)
  8 root.grid_rowconfigure(0, minsize=400)
  9 root.grid_columnconfigure(0, minsize=400)
 10
 11 root = Tk()
 12 TkSync(root)
 13 root.mainloop()


When I run that, it sizes right to start out... but then it won't get
any bigger. I've tried various different combinations and nothing has
worked quite right.

TIA,
Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter Grid, Listbox expand

2009-02-26 Thread W W
Aha! I found the key - I was missing the weight argument:

  1 from Tkinter import *
  2 import os, shutil, tkFileDialog, tkMessageBox
  3
  4 class TkSync:
  5 def __init__(self, root):
  6 self.sbox = Listbox(root)
  7 self.sbox.grid(row=0, column=0, sticky=N+S+E+W)
  8 root.grid_rowconfigure(0, minsize=400, weight=1)
  9 root.grid_columnconfigure(0, minsize=400, weight=1)
 10
 11 root = Tk()
 12 TkSync(root)
 13 root.mainloop()


Works perfectly.
-Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Ctrl-C (unix) in python

2009-02-18 Thread W W
On Wed, Feb 18, 2009 at 4:44 PM, pa yo payo2...@gmail.com wrote:

 I am  running my TwitterWiki bots in infinite loops but can't find
 an easy way to turn them off gracefully once I have started them. At
 the moment I have to go into the terminal window where they are
 running and type Ctrl-C. (I am running Ubuntu 8.10 and python 2.5.2)

 I was thinking that I could get the bot script to read a text file at
 the start of the main loop and have a separate script writing the
 exit order to the same text file but before I get too involved
 with this I wanted to know if there  was an  built-in function to
 switch scripts on and off.


Unless you want to play with sockets, that's probably the easiest way to do
it that I know of.

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


Re: [Tutor] List weirdness

2009-02-13 Thread W W
On Fri, Feb 13, 2009 at 11:01 AM, bob gailer bgai...@gmail.com wrote:

 Moos Heintzen wrote:

 snip I guess I can't reference [0] on an empty list. (I come from a C
 background.)

 Can you have an empty array in C? If so, it does not have any elements, so
 you can't refer to element 0.


I think the OP was confusing an empty array in C (something like int foo[10]
= {}; ) where memory is allocated, just not used, to an empty list in
Python.

AFAIK, creating an empty list in python is a lot more similar to creating an
empty vector in C++.

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


Re: [Tutor] IDLE vs PythonWin

2009-02-10 Thread W W
On Mon, Feb 9, 2009 at 9:29 PM, Eric Dorsey dors...@gmail.com wrote:

 You can call a .py script from the command line, and it will run there. So,
 in Windows XP: Start  Run  type CMD
 Vista: Start  type CMD into the Start Search field.
 If you're in Linux, get to a Terminal.
 In Windows another window will open with something
 like...C:\FolderWithMyPyFile
 Linux something like m...@ubuntu-desktop:~$

 Assuming uberprogram.py is in the current folder, you can then just type
 into the command prompt like C:\FolderWithMyPyFileuberprogram then hit
 enter

 You can see the results of the program right in the command prompt/terminal
 window.


Unless your program doesn't wait for any input before quitting.Then you just
have to add a line like this:

raw_input(Press ENTER to quit)

and that will block until you hit return.
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple PassGen

2009-02-09 Thread W W
On Mon, Feb 9, 2009 at 3:35 PM, Kayvan Sarikhani ksarikh...@gmail.comwrote:

 Hello Tutors,
 snip  I thought that maybe adding print random.choice(pool).strip()
 might work but not having any luck with that. Is the output this way, simply
 because of the nature of the range, or can anyone point my in the right
 direction? Thanks in advance!


It's actually not the range but the print function. Print automatically
prints a newline. If you were to create a string of what print does:

print 'foo'

'foo\n'

However, adding a trailing comma will eliminate that. It will still add a
trailing space however. A better option would be like Marc suggests,
although you have to do concatenation:

mystr += random.choice(pool)

You do have some other options though. Create a list and join it with '':

In [148]: x = ['a','b','c']

In [149]: ''.join(x)
Out[149]: 'abc'

Create a list, convert it to tuple, and use string formatting:

In [151]: '%s%s%s' % t
Out[151]: 'abc'

Use sys.stdout.write instead:

In [154]: for y in x:
   .: sys.stdout.write(y)
   .:
   .:
abc

and a host of other options. The simplest is probably the concatenation
though ;)
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Closing and Open File--TkFileDialogs

2009-02-07 Thread W W
On Sat, Feb 7, 2009 at 9:09 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Yes, amazingly enough, I'm quite familiar with basic file operations. :-)
 I'm certainly no expert at all variations of it.
 snip
 Now for a related question. I'm using Win XP. One of the arguments is the
 default_path. I would like it to be the same folder the program is in. How
 do I do that? c:/., ./,  or some variation?


IIRC you would use .

In [4]: import os

In [5]: os.curdir
Out[5]: '.'

or of course, os.curdir would probably be more portable.

And just a little tidbit I discovered while working with a program that
would change directories, but I was running from inside Ipython, if you add
this to the beginning of your file:

import os
startpath = os.path.abspath(os.curdir)

and then this to the end:
os.chdir(startpath)

then it will keep your ipython environment in the directory you run the file
from.

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


Re: [Tutor] Designing a Dialog in Python

2009-02-06 Thread W W
On Fri, Feb 6, 2009 at 3:12 AM, Alan Gauld alan.ga...@btinternet.comwrote:

 Wayne Watson sierra_mtnv...@sbcglobal.net wrote

 Signature.htmlWhen I used VBasic many years ago, it had the ability to
 design a dialog and then attach it to the code. Is there something like this
 available for Python?


 However most Python programmers still seem to build their GUIs using
 vanilla code rather than a visual editor.
 If you don't  need the visual design tools then you can design dialogs etc
 in your favourite editor and for that Tkinter/Tix come as standard.snip


I'm aware of a visual design tool for Tkinter. I tried it (nowhere near as
polished as delphi/VB of course) for about 30 seconds before deciding I
didn't need the visual design tool. I forget what the editor was called
though . doh!

Of course you could always roll your own in Tkinter ;)
-the other Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] struct question

2009-02-03 Thread W W
On Tue, Feb 3, 2009 at 6:25 PM, bob gailer bgai...@gmail.com wrote:

  struct.calcsize('s')
 1
  struct.calcsize('d')
 8
  struct.calcsize('sd')
 16

 Why? Should not that be 9?


 struct.calcsize('ds')
9

at least on the current box I'm running. It also gave me this:

 struct.calcsize('sd')
12

so I must confess suspicion...

HTH though,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] methods split and join in sequence

2009-01-31 Thread W W
On Sat, Jan 31, 2009 at 9:09 AM, David ld...@gmx.net wrote:

 Dear list,

 many thanks for all your help - much appreciated.
 Today I have continued reading Harrington, and produced the following code,
 which works flawlessly.
 I wonder, though, how I could join all the supplied words with underscores
 _without_ making use of split first? This I didn't manage. snip


I'm really not sure if you could. Strings don't support item reassignment,
so you can't do it this way:

 In [1]: x = 'foo bar'

In [2]: x[3] = '_'
---
TypeError Traceback (most recent call last)

C:\Documents and Settings\Wayne\ipython console in module()

TypeError: 'str' object does not support item assignment

But there are other string methods available, such as the replace method.
http://docs.python.org/library/string.html
for the string documentation.

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


Re: [Tutor] IDLE vs PythonWin

2009-01-31 Thread W W
On Sat, Jan 31, 2009 at 9:56 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Hi, sorry, but I have no idea what vim is, let alone how to use any of the
 features. I'd still like to know why pythonwin prints almost completely
 blank pages. vim=vi(m), linux??


VIM = Vi IMproved = vim +- vi. Basically, vim is just an upgraded vi.
Available at www.vim.org - it's just a text editor (that happens to be
phenomenally powerful and the vi(m) disciples have waged holy wars against
the followers of emacs since the beginning of time... or at least since vi
and emacs got popular. It's not too unlike Israel vs. Palestine. The best
way to avoid bad feelings is to agree that each person prefers a different
belief system and move on to the awesome stuff like actually programming ;)
) that certain people prefer because of its ability to be customized to fit
ones needs and wants. If you are interested in learning vim theres a vim
tutor that comes with your install of vim (available on Windows, Mac, and
Unix systems).

When it comes to the pythonwin problem, I'm almost completely inexperienced.
If you have the ability to print to pdf that's an inexpensive way to try
and troubleshoot. You can also take a look at the print preview.

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


[Tutor] Tkinter program start with focus?`

2009-01-31 Thread W W
Hi,
I'm running into a problem that's bugging me because I know a program used
it, I just can't find which one it was...

I want my Tkinter program to start with the focus, but I can't remember the
command.

TIA,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDLE vs PythonWin

2009-01-31 Thread W W
On Sat, Jan 31, 2009 at 8:45 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Did I miss a response here?

 Wayne Watson wrote:

 vim? I'm looking at the interactive window now. Here are two choices for
 what you say:
 1.
 alt-tab vim
 Traceback (  File interactive input, line 1
 alt-tab vim
   ^
 SyntaxError: invalid syntax

 2. Pressing the alt-tab keys moves me to the next Windows window, which
 happens to contain my mail window.

 I'm putting an image here. It may not get through to tutor.


 ALAN GAULD wrote:

   I'm not familiar with these acronyms. MDI, SDI,

 MDI = Multi Document Interface - has many windows within one single outer
 window.
 This was MS Standard for apps from Windows 2 through to Windows 95.

 SDI = Single Document Inteface - has each document within its own window.
 This has been the preferred styule since XP (between 95 and XP I think the
 preferred style was up to the developers!)

 Alt-Tab and up-arrow for navigating between windows/commands
 works for me :-)

  As soon as I hit, alt-tab, Win moves between all the icons on my screen.
  There's not chance to press an up arrow.

 Alt tab switches windows
 Up/Down arrow moves up/down the command history within a window

 So a typical session goes like:

 Experiment at  prompt
 Alt-Tab to vim
 Edit  save file in vim
 Alt-Tab to Console
 use up arrow to retrieve last command
 execute last command(ie run the script)
 Alt Tab to vim to fix bugs or  to try out new ideas snip


I think you may have misunderstood Alan.

He has open a vim editor and a python prompt. So he might do something like:

 def test():
... print Hello, does +  this work?
...
 test()
Hello, does this work?

in his interactive shell. So now he knows string concatenation works so  he
might hit alt+tab to his open vim window and there add something like this:

def salutation(fname, lname):
print Good morning,  + fname +   + lname + . Welcome to my
program!

Or of course he could experiment with the actual bit of code he's trying to
write, but the illustration still stands. Then he saves his code in vim and
runs the script in the shell (in Ipython you'd use the magic function %run,
I'm not sure about the regular shell), to see how well his code works with
the rest of his program.

That's the same way I edit my code - vim + Ipython gives me all the tools I
need. The nice thing about working with another shell like that is you can
use your favourite editor, whether it be vim, or emacs, or gedit, or
notepad++ or scite, or MS Visual Studio, or notepad, or wordpad... I'm sure
you get the picture ;)

Heck, you can even use pythonwin the same way.

HTH,
Wayne
image/jpeg___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with nested for-in

2009-01-29 Thread W W
On Thu, Jan 29, 2009 at 5:06 AM, emmanuel.delaborde 
emmanuel.delabo...@cimex.com wrote:

 Hello,

 I have the following snippet :

 lines = csv.reader(open(CATEGORY.csv,r))
 lines2 = csv.reader(open(CATEGORYLIST.csv,r))

 old_cats = []
 for line in lines:

  print line


stories = []
for line2 in lines2:

  print line2


if line2[1] == line[0]:
stories.append(line2[0])
old_cats.append((line[0],line[2], stories))


 what happens is that

 for the first elt of lines, the nested for in runs fine
 but then never seem to run again while the top level loop iterates through
 the rest of lines

 consequently stories accumulate nothing...

 Can someone explain please ?


I would try adding the two print statements above to your code. It might
give you an idea about what's going on. It would also be helpful to provide
us with some of your original data and the data you get once you've run the
program.

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


Re: [Tutor] Find a Word in *.py (Win XP)

2009-01-28 Thread W W
You know, it probably wouldn't be terribly difficult to write the search in
python. Then you *could* find strings inside rather easily.

HTH,
Wayne

On Wed, Jan 28, 2009 at 9:30 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  Thanks. I'll post a msg to a XP group about this. I suspect Python hashes
 the code somehow.

 Findstr? Wow, that's got to be old. Where did you find that?


 Alan Gauld wrote:


 Wayne Watson 
 sierra_mtnv...@sbcglobal.netsierra_mtnv...@sbcglobal.netwrote

 Just using the standard Win XP Pro folder search.
 I target the folder with my py programs, use *.py to
 search, and specify I'm looking for angle in the files it finds.


 Yes, I get the same behaviour!
 I tried searching for 'import' which should be almost every file!
 It came up blank. When I tried tkinter it found one file with Tkinter
 in the file name. It seems it is not looking inside the file!

 Weird.

 However the DOS command findstr works as expected!

 Alan G

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


 --

Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

  (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)*   
   Copper and its alloys have been found effective in hospital
  sinks, hand rails, beds, ... in significantly reducing
  bacteria. Estimates are 1/20 people admitted to a hospital
  become infected, and 1/20 die from the infection.
-- NPR Science Friday, 01/16/2009 *
 Web Page: www.speckledwithstars.net/


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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tk+Ipython unexpected behavior

2009-01-26 Thread W W
Hi all,
I'm going through An Introduction to Tkinter by Fredrik Lundh and came
across (what seems to be) some slightly unexpected behavior. I'm editing the
python file with my favorite text editor, and using the %run magic function
in Ipython to test my program(s). On the second example(pg 4 of the PDF),
the frame.quit method is bound to a quit button. When I double click the .py
file to run it, it closes when the quit button is pressed. But with Ipython,
when the quit button is pressed, it unblocks the Ipython input but doesn't
actually quit the window. A call to root.quit() will not close the window,
only a call to root.destroy().

I'm not terribly worried about it, but I'm curious if it should be
considered a bug or simply unexpected behavior.

-Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding the End of a Def?

2009-01-24 Thread W W
On Sat, Jan 24, 2009 at 7:06 AM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  If you are familiar with vi and C, one could enter a simple keystroke and
 jump from an opening paren to the corresponding closing one.

 I've long forgotten most of C, but here's a rough segment of a program:

 main()
 (
 while (x ==True)
 (
a =5;

 )
 ...
 )
 If your cursor was on the second (, pressing a key would take you to the
 third one. I want something like it for def. Where's the end of the def.
 Some def blocks are so long it's almost impossible to find where they end.


Presuming, of course, that your def statement is followed by another,
finding the next def would get you there.

Other than that... you may just have to figure out how to write your own
bindings.
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Defining bit type

2009-01-24 Thread W W
On Sat, Jan 24, 2009 at 9:38 AM, Vicent vgi...@gmail.com wrote:

 snip
 So, maybe I can adapt the definition of bool type, I don't know...
 Anyway, I want to manage 0's and 1's, not Falses and Trues.snip


Well, I can think of something that might be of some help:

In [18]: bit = {True:1, False:0}

In [19]: bit[True]
Out[19]: 1

In [20]: bit[False]
Out[20]: 0

In [21]: bit
Out[21]: {False: 0, True: 1}

In [22]: x = False

In [23]: bit[x]
Out[23]: 0

That might give you something to work with. Anyway, HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Possible to search text file for multiple string values at once?

2009-01-23 Thread W W
On Fri, Jan 23, 2009 at 12:38 PM, bob gailer bgai...@gmail.com wrote:

 Scott Stueben wrote:

 Hi all,

 I understand that python excels at text processing, and wondered if
 there is a way to use python to accomplish a certain task.  snip
 I would love to set up a script to parse a file and show results from
 a list of strings.  Is this possible with python?



 Yes - and also possible with almost all other programming languages.
 Here is one of several ways to do it in Python:

 for first_name in ('Bob', 'John', 'Joe', 'Jim', 'Fred'):
  if  first_name in text:
   print first_name, 'found'


Another option, if you really like sql, is to import sqlite3 and then parse
your text file into a sqlite database. That's probably overkill, of course.
But it's a possibility.
It really depends on what matters most. Speed? Comfort(with syntax)? Ease of
use? That will give you an idea of which tools you should use.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Possible to search text file for multiple string values at once?

2009-01-23 Thread W W
On Fri, Jan 23, 2009 at 1:11 PM, Scott Stueben sidewalk...@gmail.comwrote:

 Thanks for the help so far - it seems easy enough.  To clarify on the
 points you have asked me about:

 A sqlite3 database on my machine would be an excellent idea for
 personal use.  I would like to be able to get a functional script for
 others on my team to use, so maybe a script or compiled program
 (Win32) eventually.


As long as everyone on your team has python installed (or as long as python
is installed on the machines they'll be using), a functional script would be
fairly easy to get rolling. Sqlite is (AFAIK) included with the newer
versions of python by default. Heck, it's on the version I have installed on
my phone! (Cingular 8525). Simply zipping up the directory should provide an
easy enough distribution method. Although, you *could* even write a python
script that does the install for them.


 As for output, I would probably like to return the entire lines that
 contain any search results of those strings.  Maybe just output to a
 results.txt that would have the entire line of each line that contains
 'Bob', 'John', 'Joe', 'Jim', and or 'Fred'.


The simplest method:

In [5]: f = open('interculturalinterview2.txt', 'r')

In [6]: searchstrings = ('holy', 'hand', 'grenade', 'potato')

In [7]: for line in f.readlines():
   ...: for word in searchstrings:
   ...: if word in line:
   ...: print line
   ...:
   ...:
Hana: have a bonfire n candy apples n make potatoes on a car lol!

Wayne: potatoes on a car?

Hana .: yer lol its fun and they taste nicer lol, you wrap a potato in
tinfoil a
nd put in on the engine of a car and close the bonnet and have the engine
run an
d it cooks it in about 30 mins

 Speed isn't as important as ease of use, I suppose, since
 non-technical people should be able to use it, ideally.


Although that wouldn't be quite so easy to use ;) Of course simple
modifications would provide a little more user friendliness.


 Maybe, since I am on Win32, I could have a popup window that asks for
 input filename and path, and then asks for string(s) to search for,
 and then it would process the search and output all lines to a file.
 Something like that is what I am imagining, but I am open to
 suggestions on items that may be easier to use or code.


Using Tkinter (again, which AFAIK comes with all versions of python) is
pretty simple.

import Tkinter, tkFileDialog, tkMessageBox
root = Tkinter.Tk()
root.withdraw()
if tkMessageBox.askyesno(Choose a file?, Would you like to choose a file
to search?):
f = tkFileDialog.askopenfile()

You could also use this method to select a file that contains search
strings, or allow the user to input them in some other way.


 Is that reasonably simple to code for a beginner?


Yes, it's fairly simple. If you've had minimal programming experience you
might encounter some bigger problems, but if you've programmed in PHP or
some other language you should find it fairly easy to pick up python, and
use all the commands you'll need.

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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread W W
On Mon, Jan 19, 2009 at 12:05 PM, Steve Willoughby st...@alchemy.comwrote:

 Is it reasonable to expect that I could use Tkinter for
 everything else, but use pygame/pymedia to handle things like
 creating a video playback window on the screen, or is pygame
 going to want to run the whole GUI event loop and screen updates
 in competition with Tkinter?

 Any general nudges in the right direction would be appreciated.
 Thanks,
 steve


As far as I know it would be a fairly reasonable expectation - you would
simply hide the Tkinter screen when you show the pygame/pymedia window.
However, I'm not nearly as versed on any of the above as a lot of folks
here, so they may be able to confirm/contradict my advice.

But with my limited knowledge, that's probably how I'd do it (unless you
have a burning desire to learn pygame).

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


[Tutor] 2.5 vs 3k?

2009-01-19 Thread W W
So, I'm curious about this whole python 3k thing. Is python migrating to 3k
only? Will 2.x no longer be officially supported?

If so/not, what are some of the arguments for migrating to 3k? What makes it
better than the python we all know and love?

Thanks for the info/comments,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating simple windows in XP

2009-01-16 Thread W W
On Thu, Jan 15, 2009 at 5:45 PM, Alan Gauld alan.ga...@btinternet.comwrote:

 You mean like doing

 import tkMessageBox
 tkMessageBox.showinfo(Window Text, A short message)

 in Tkinter? :-)

 OR

 res = tkMessageBox.askokcancel(Which?, Ready to stop?)
 print res

 At that level Tkinter is pretty easy too.


After trying that and getting the mildly annoying root window to pop up I
did a quick search and found how to hide that window.

from Tkinter import Tk
root = Tk()
root.withdraw()
tkMessageBox.showinfo(Window, Root window is gone!)

If you need it back, root.deiconfiy() will show the window again.

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


Re: [Tutor] running debugging in python interactive shel

2009-01-15 Thread W W
On Wed, Jan 14, 2009 at 8:18 PM, Che M pine...@hotmail.com wrote:

  snip
 I'd like to add to this question and expand it:  can anyone point me to
 a good resource on debugging *generally*?


The first result on Debugger tutorial on google sent me to this:
http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html

Though it's for a specific program, it seems to have some good general
purpose advice. Personally, I've never had the need for a debugger (maybe
because I'm not writing complicated enough programs) - a simple print
statement (in the right spot) tends to take care of all of my debugging
needs.

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


Re: [Tutor] Working with IDLE in XP, Set Up for A New Program

2009-01-11 Thread W W
On Sat, Jan 10, 2009 at 8:08 PM, Wayne Watson
sierra_mtnv...@sbcglobal.netwrote:

  I immediately answered my own question by clicking on a link that took me
 to a web site with the pdf; however, it looks like I installed Python 2.6.
 It'll be easy to uninstall, but I don't see 2.5 -- yet.


http://www.activestate.com/store/download.aspx?prdGUID=b08b04e0-6872-4d9d-a722-7a0c2dea2758

They have python 2.5.2... something. On the right hand side, as of this
message, anyway.

HTH,
The Other Wayne


 Wayne Watson wrote:

 Hi, this is a continuation of my post from way back in August. I just
 installed Pythonwin. It's showing me a window for Dive into Python.
 Apparently, it's an extensive document. How do I determine how many pages
 there are, and do I print the whole thing section by section? Maybe there's
 a PDF?

 ALAN GAULD wrote:


  Where do I get pythonwin?

 Either download the Windows extensions as linked from the
 Python.org web site, or even better download and install the
 Activestate.com version of Python. Its free but you must register.
 It has lots of goodies and uses pythonwin as the default IDE.
 I use that on all my Windows PCs.

 Alan g

 Alan Gauld wrote:


 Wayne Watson 
 sierra_mtnv...@sbcglobal.netsierra_mtnv...@sbcglobal.netwrote

 would like to know if there's an easier way to start it than what I use? I
 pick on a py file, and then use the pull down menu, right-click, to select
 IDLE.


 Yes, it should be on the Start menu possibly listed as Python GUI.

 Or you can set up a shortcut to it by selecting idle.pyw in explorer and
 creating a shortcut and dragging it to your desktop.

 Or you could do yourself a favour and get the Pythonwin extensions and use
 Pythonwin instead. IDLE is fine for a cross platform IDE but it is ugly and
 less feature rich than Pythonwin. And the pythonwin installer sets up the
 menus etc for you.

 HTH


 --

Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet   
  We are in a race between education and catastrophe.
  – H.G. Wells

 Web Page: www.speckledwithstars.net/


 --

Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

  (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)*   
 What killed the electric car? Expensive batteries did.
   -- Physics for Future Presidents, Richard A. Muller***  
   Web Page: www.speckledwithstars.net/

  --

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


 --

Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

  (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)*   
 What killed the electric car? Expensive batteries did.
   -- Physics for Future Presidents, Richard A. Muller***  
   Web Page: www.speckledwithstars.net/


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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do we upload multiple files simultaneously?

2009-01-10 Thread W W
On Sat, Jan 10, 2009 at 4:19 PM, Lie Ryan lie.1...@gmail.com wrote:

 On Fri, 09 Jan 2009 21:48:51 -0800, john dow wrote:

  Dear  All,
 
  I a newbie to python...
 
  my problem is to upload more than one file on a single go. I have an
  option open is using some FTP client...
 

 You might be interested with Twisted.

 Alternatively you might also be interested with threading or
 multiprocessing and also urllib.


Another option would be a list of files to upload, i.e.
def upload(filename):
#implementation here

files = ['file1.txt', 'file2.txt', 'file3.txt']
for file in files:
upload(file)

Of course there are various different ways you could perform that type of
action, but that should point you in the right direction.
HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Top posters to tutor list for 2008

2009-01-04 Thread W W
I think I find it most interesting that the greatest percent is still under
15% and then it tapers rapidly. I'm curious what % of people posted 5 or
less messages... perhaps it will become a personal project somewhere down
the road ;)

-Wayne

On Fri, Jan 2, 2009 at 7:28 AM, Kent Johnson ken...@tds.net wrote:

 On Fri, Jan 2, 2009 at 8:13 AM, Sander Sweers sander.swe...@gmail.com
 wrote:
  On Fri, Jan 2, 2009 at 13:52, Kent Johnson ken...@tds.net wrote:
  Or ask more questions, that works too!
 
  So you and Alan ask the most questions ;-)

 No, that honor goes to Dick Moores. He is in the top 10 in 4 of the
 last 5 years!

  Thanks to all the Tutors for year of great support :-)

 You're welcome, we couldn't do it without you!

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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Repply

2008-12-27 Thread W W
On Sat, Dec 27, 2008 at 3:42 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 Its C rather than C++.
 The  in include statements are a variation on the  which can also be
 used.
 The differences are subtle and have to do with the search path I think. But
 its
 been so long since I did serious C/++ I can't recall exactly!


It's only been about 2 weeks since I've been in class so that's a topic on
which I can expound.  searches the current directory before searching in
the default library. It's pretty similar to the python import behavior,
AFAICT.

And now you know
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] listen in on other program's tcp connections

2008-12-16 Thread W W
On Tue, Dec 16, 2008 at 12:57 AM, xbmuncher xboxmunc...@gmail.com wrote:

 On windows XP, I'm running a program that sends TCP connections on port
 5039. I'v ran wireshark to determine this. I want to create a simple program
 that listens for these connections and intercepts and then turns the data
 transferred into a string. From there I'd obviously like my program to act
 and manipulate those strings, but for now just spitting out that intercepted
 TCP data is good enough.

 I was reading up on Twisted. http://twistedmatrix.com/
 Can someone get me started on how to do this with twisted framework or
 anything else?


I've never done anything like this specifically... but my guess is that it's
pretty similar to creating a proxy.

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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-16 Thread W W
On Mon, Dec 15, 2008 at 9:56 AM, Benjamin Kaplan
benjamin.kap...@case.eduwrote:

 It's not a question of sensibility. It's a question of purpose. The Zen is
 the philosophy of a language that tries to be easy to learn and easy to use.
 Python is used by programmers who want to experiment with it, but who
 usually know enough not to os.system(rm -r /) or anything similar.
 Windows, on the other hand, wants to hide everything that can potentially
 ruin the system as deep as possible so that many of the idiots who use that
 system don't do stupid things like delete the registry, wipe the environment
 settings, turn off the Nag Screen (UAC), and other things of that nature


But if it were sensible, it would (like certain other OS's) make it more
difficult to have built-in permissions that allow you to totally hose the
system, i.e. it would be secure.While it may not technically be using the
same comparison criteria we do, Python still gives you the proper result:

In [5]: 'obfuscation' is not 'security' and 'obfuscation' != 'security'
Out[5]: True

I think that's an important concept for programmers to realize. Allowing
people to break things if they fool around enough is not a very sensible, or
secure way of running things. And if you're writing OSes, the sensible thing
is to write secure code. And if you're writing programs for general
consumption, it's /also/ best to write secure code.

That's my 2c anyways :)
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problems finding position in list and changing it for GO game

2008-12-15 Thread W W
On Mon, Dec 15, 2008 at 10:01 PM, Lee Meredith tesujicam...@gmail.comwrote:

 snip
 the MOUSEBUTTONDOWN gives the black0 XandYpositions with the*.append*
 how do I reference the address in the list by using XandYpositions
 Then replace them or take it out off the list

 This code puts out an error when you hit the letter b


This error is pretty verbose, as most python errors are:


 Traceback (most recent call last):
   File C:/Users/Lee/Desktop/pyGame01/GO/GO_1_2_3.py, line 46, in module


This line tells you that the offending statement, the one that broke your
program/contained a bug is on line 46. Usually this is a pretty good place
to start looking.


 for stone in len(black0):


That tells you the statement that broke


 TypeError: 'int' object is not iterable


This line tells you /why/ it broke, which is usually the most important bit,
and this one gives you some good information. First off, it tells you the
type of error, in this case TypeError. AFAIK, this means you tried to do
something with a type that isn't allowed. In this case you tried to iterate
over an integer. This doesn't work.

Would you expect this to work?
for num in 7:

Hopefully your experience with python will tell you that it would be silly
to think of such a thing.However, if you were to say:

for num in range(0, 7): - that would be a little more sane. In this case,
you are performing something similar to the prior example: you're trying to
iterate over a single integer. len() returns the length of the list as an
integer value.

If you look at some of your other statements you have for white in white0:
- a list is iterable, and white0 is a list.

I hope this helps,
Wayne




 Which I'm not really sure what that means or how to remedy it as well

 Thank you everyone

 ## geting there black and white stones alternate now the issue
 ## of taking the stones off the board
 ## Or more precisely to .insert into the list at an address that I detected
 by finding the X. and the Y. by using the
 ## if event.pos == range( black0[stone][0] - (stoneWidth/2),
 black0[stone][0] + ((stoneWidth/2)+1)):
 import pygame
 from pygame.locals import *
 from sys import exit
 pygame.init()
 screen = pygame.display.set_mode((758, 758), 0, 32)
 ##Color
 color0 = (0,255)

 b = 0

 white0 = [] #white0
 black0 = [] #black0

 stoneWidth = 20

 while True:
 pressed_keys = pygame.key.get_pressed()
 for event in pygame.event.get():
 if event.type == QUIT:
 exit()
 if event.type == MOUSEBUTTONDOWN:##makes a variable out of the X.
 and Y. coordinates
 if b==0:
 b=1
 black0.append(event.pos)##black0.append [X. and Y.]
 black1.append(event.pos)
 print black points1
 print black0
 print
 else:
 b=0
 white0.append(event.pos)
 white1.append(event.pos)
 print white points
 print white0
 print
 if event.type == KEYDOWN:
 if event.key == K_b:
 print cut black
 for stone in len(black0):##I'm not sure here either   is
 this the way I would look for detection of mouse in the range
 Circleif event.pos == range( black0[stone][0] -
 (stoneWidth/2), black0[stone][0] + ((stoneWidth/2)+1)):
 ## this is where I get confused what should I do
 
 ## black0.insert(event.pos,0)
 if event.pos == range( black0[stone][1] -
 (stoneWidth/2), black0[stone][1] + ((stoneWidth/2)+1)):
 ## this is where I get confused what should I do
 
 ##black0.insert(event.pos,1)

 screen.fill((229,181,83))
 screen.lock()
 for white in white0: #you're drawing
 pygame.draw.circle(screen, (color0[1],color0[1],color0[1]), white,
 20)
 for black in black0:
 pygame.draw.circle(screen, (color0[0],color0[0],color0[0]), black,
 20)
 screen.unlock()
 pygame.display.update()



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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to run a process forever

2008-12-10 Thread W W
while True:
is also a common way to make your program run forever. Although you still
need to create some sleep/wait function or it will eat up your available
processes (so I'm told).

-HTH,
Wayne

On Wed, Dec 10, 2008 at 12:28 PM, Steve Willoughby [EMAIL PROTECTED]wrote:

 On Wed, Dec 10, 2008 at 12:23:48PM -0600, shawn bright wrote:
  Hey gents,
 
  I have an interesting problem. I need to have a python script start
  when a computer boots up, and i need it to run forever.
  I also am going to run a script by cron that will check to see if the
  process is running, if not, i need a python script to execute
  the script.

 Maybe I'm misunderstanding your meaning, but usually programs which do
 this don't do anything unusual other than... well... simply run forever
 in the background (launched from the startup scripts or cron, disassociated
 from any TTY, of course).  A watchdog re-launcher cron script is also
 not uncommon.

 If your script isn't actively doing something it's good to put it to
 sleep until some interesting event (or timer) wakes it up.

 Was there something beyond that you were looking for?

 --
 Steve Willoughby|  Using billion-dollar satellites
 [EMAIL PROTECTED]   |  to hunt for Tupperware.
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] importing images and sound

2008-12-02 Thread W W
On Tue, Dec 2, 2008 at 2:02 PM, Steve Willoughby [EMAIL PROTECTED] wrote:

 snip
 That depends on what GUI toolkit you're using.  If you're
 going to be doing a lot with sound and images, particularly
 video clips, you might want to look at pymedia or pygame


Pyglet is another option.

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


Re: [Tutor] Tutor Digest, Vol 58, Issue 2

2008-12-01 Thread W W
Try this:

 for x in xrange(3, 0, -1):
   : print x
   :
   :
3
2
1

HTH,
Wayne

On Mon, Dec 1, 2008 at 2:20 PM, WM. [EMAIL PROTECTED] wrote:

 Stooges.py

 i,j,k = 3,3,3
 while i != 1:
print 'Larry, Moe  Curly Joe!'
i -= 1
while j != 1:
print 'Go Mad!!'
j -= 1
 while k != 1:
print 'Go-go bad-bad!!'
k -= 1
 print '\nBye-bye.'

 I am trying to learn loops.  These nested 'whiles' work OK but I would like
 to wrap this script in a 'for' loop. I have not been able to make that work.


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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 58, Issue 2

2008-12-01 Thread W W
On Mon, Dec 1, 2008 at 5:24 PM, Alan Gauld [EMAIL PROTECTED]wrote:

 snipSince the OP isn't using the loop counter a simpler solution
 is simply

 for x in range(3):


but the OP was looping from 3 to 1, and that's the easiest way I knew of.

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


Re: [Tutor] 'for' loops

2008-12-01 Thread W W
On Mon, Dec 1, 2008 at 6:44 PM, WM. [EMAIL PROTECTED] wrote:

 I recently asked a question about 'for' loops, expecting them to be similar
 to 'for-next' loops. I have looked at several on-line tutors but  am still
 in the dark about what 'for' loops do.
 Does anyone have a plain English about the use of 'for' loops?
 Are 'while' loops the only way Python runs a sub-routine over  over?


For loops are mainly used when you want a specific number of iterations,
such as looping over the elements of a list. In C/C++ you would do something
like this:

int myarray[] = {1, 2, 3, 4, 5};
for(int x = 0; x  5; x++)
printf(%d, myarray[x])

In python it would be much cleaner:

myarray = [1, 2, 3, 4, 5]
for x in myarray:
print x

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread W W
On Tue, Nov 25, 2008 at 6:43 AM, Jason DeBord [EMAIL PROTECTED] wrote:


 The following for example:

 from mod_python import apache

 def handler(req):
 req.write(Hello World!)
 return apache.OK

 Frankly, I don't understand what is going on in the above. This is a bit
 different compared to what I am used to.


I don't know if you did much OOP (Object Oriented Programming) in PHP, or
anything else, but that's what python does, and does well. There are some
tutorials out there that explain what objects really are... but I read
somewhere that in python /everything/ is an object, and that's pretty much
true to my experience.

The line starting with from is similar to an include statement in php.
Though what you're doing is including apache that happens to be inside the
mod_python library.

The next line:

def means you're defining a function (or method, if it's in a class, where
it would be def handler(self, req), but that's another story)

handler is the name you're calling the function and req is the name of your
argument. At this point, it really doesn't matter what req is... it's just a
name that will point to (or become a copy of) whatever you pass to it.

In this case, you're passing it a class that has the method write.
Consider this example(I'm using the IPython active interpreter, so you see
In instead of ):

In [15]: class foo:
   : def write(self, mystr):
   : print mystr
   :
   :

In [17]: def handler(req):
   : req.write(Hello World!)
   :
   :

In [18]: x = foo()

In [19]: handler(x)
Hello World!

And then return apache.OK is returning... well, the object OK in the
apache class.

Of course, I've never used mod_python/apache, that's just me applying what I
know about python, so I may not be 100% accurate, but I don't think I'm too
far off.


 So, my question, would you all please point me to some introductory
 resources, tutorials, books, that focus on Python programming for the web? I
 am eventually going to interface with some web services, notably Amazon Web
 Services. Also, I'd like to write some server side scripts to serve as a
 backend to some Adobe AIR apps.


If you plan on doing much command line/admin type stuff, I'd recommend
Python for Unix and Linux System Adminstration by Noah Gift  Jeremy M.
Jones, available through O'Reilly, at least as one resource (ISBN:
978-0-596-51582-9)

Noah spoke at our un-conference in October, and I learned a lot, hence, my
recommendation.

It does a great job of throwing you into a lot of various administration
tasks, which instruction can be applied to (and is also useful for) many
other tasks.

Definitely check out the links others have provided, they'll be packed full
of helpful information, and I hope this helped as well.

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


Re: [Tutor] My horrible looking program needs improvement.

2008-11-24 Thread W W
On Mon, Nov 24, 2008 at 10:00 AM, Peter van der Does [EMAIL PROTECTED]
 wrote:

 I wrote my 1st Python program and it works as I want it to work but
 ,IMHO, it looks horrible.


Nothing to be ashamed of, unless you don't mind it looking horrible. The
fact that you want a clean program is a good sign!


 snip


 Why I think it looks horrible:
 Everything is in main(), I would like to use functions but ran into
 problems with the scope of my variables.
 The CLI arguments check is just a bunch of IF's


You would probably benefit from using a class then (especially if you have
worries about your main program looking clean).

You can create global class variables that each of the methods/functions
have access to with the self. - for instance

In [11]: class IP:
   : address = 192.168.1.1
   : def printAddress(self):
   : print self.address
   :
   :

In [12]: x = IP()

In [13]: x.printAddress()
192.168.1.1
---

Then you just declare a new instance of your class (see In[12]) and you have
access to all its methods and variables;

In [15]: x.address = 127.0.0.1

In [16]: x.printAddress()
127.0.0.1


 Is this the place where somebody could go over my program and give
 some pointers on how to improve the structure or is there a forum out
 on the Net that can help me out.


I don't know about anyone else, but I suspect most people are at least as
busy as myself, but perfectly willing to help answer your questions, but I
doubt anyone has the time (even if they want) to re-write your program /for/
you, but we'll be glad to help if you get stuck on a problem (or even need
pointers on where else to look, if Google or your favourite search engine
fails to turn up any information)

Using a class should really help clean up your program and help eliminate
your scope problems. Here's a nifty little tutorial on python classes:
http://www.diveintopython.org/object_oriented_framework/defining_classes.html

Give classes a try and see if helps. If you're still having issues or you
don't understand something, feel free to ask!

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


Re: [Tutor] file locations

2008-11-24 Thread W W
On Mon, Nov 24, 2008 at 1:10 PM, Jeff Peery [EMAIL PROTECTED] wrote:

 Hello,
 I have a wxapp from which I would like to execute another wxapp. the
 'child' wxapp is located in a sub directory of the 'parent' wxapp. The
 problem I'm having is that I execute the child app from the parent app and
 it cannot find the modules/images/files etc that it needs because it is
 looking in the parents directory location and not its own. I want to keep
 the child wxapp in its own sub directory for organizational purposes, but
 what is the best way to deal with this problem?


I don't know much (read just about zero) about wxapp, but at first blush I
would think you should be able to give an absolute directory for all the
modules/images/files, etc. rather than relative. Though I have no clue how
you would do that.

HTH, good luck,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open Source database software

2008-11-24 Thread W W
On Mon, Nov 24, 2008 at 6:19 PM, Mike Meisner [EMAIL PROTECTED] wrote:

  Y'all have been so good with suggestions on my programming problems in
 the past, I wonder if anyone could provide a suggestion on a more general
 topic.
 snip5.  And, everything either in Python or with APIs that Python can
 easily use.

 Has anyone used products that would meet my needs?


I haven't used anything, but you can connect to mysql databases with python,
from what I've read it seems to have all the bells  whistles (and then go
ahead and add the ability to do whatever you want/can do with python).

I'm sure there are plenty of folks with more experience, but that's
something to get you started!

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


Re: [Tutor] the sense of brackets

2008-11-22 Thread W W
On Sat, Nov 22, 2008 at 9:42 AM, spir [EMAIL PROTECTED] wrote:

 I have long thought [] /simply/ is a list constructor syntax.
 What do you think of the following?

 t = aze
 print t, list(t), [t]
 print list(list(t)), list([t]), [list(t)], [[t]]
 ==
 aze ['a', 'z', 'e'] ['aze']
 ['a', 'z', 'e'] ['aze'] [['a', 'z', 'e']] [['aze']]

Consider the following:
In [1]: list(Hello)
Out [1]: ['H', 'e', 'l', 'l', 'e', 'o']
and the list docstring:
list() - new list
list(sequence) - new list initialized from sequence's items
so list(list(t)) makes perfect sense: list(t) is ['a', 'z' ,'e'] and
list(list(t)) simply creates a new list initialized from that list's items
HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script from another folder

2008-11-12 Thread W W
On Wed, Nov 12, 2008 at 10:27 AM, [EMAIL PROTECTED] wrote:

 Suppose I have a python script in /usr1/myID/bin and I want to run it from
 another folder. If I enter

 python ~myID/bin/myscript

 that works. Is there a way to get by with

 python myscript

 or even

 myscript.py

 I've tried specifying the PYTHONPATH
 environmental variable but it seems to be used only for importing modules


it looks like you're on linux - so at the beginning of your script put
#!/usr/bin/env python (I believe) and then chmod +x myscript.py

then you can call it from the command line.

Alternatively you could create a shell script that would execute it with
python.

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


Re: [Tutor] Question

2008-11-10 Thread W W
On Mon, Nov 10, 2008 at 9:40 AM, Alan Gauld [EMAIL PROTECTED]wrote:

 snip

What does nano do that vi (or emacs) doesn't? Given that vi is the
 standard editor on *nix ity would seem the obvious choice. But everyone
 seems to be using nano? Why?


AFAIK, it's a little smaller/faster than emacs... but since I'm a vi(m) fan,
I'm probably the wrong person for the question ;)

-Wayne



 PS. I should explain that I used to use Unix a lot but it was before nano
 appeared to proliferate so I never used it. Now I only use *nix occasionally
 but nano is everywhere it seems.

 Alan G.


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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread W W
On Fri, Nov 7, 2008 at 4:12 AM, Eric Abrahamsen [EMAIL PROTECTED]wrote:


 snip

 Also, are there other concepts that I should focus on? Frankly, I'm a bit
 bored because I've hit this ceiling, and I'm not really sure where to go to
 next.


If you want to learn all sorts of new and exciting things, I'd suggest
learning about cryptography, and writing attacks (on your own data) as a
method of learning more. It's fun, challenging, and there's a real world
application for it, if you happen to enjoy any type of security.

my 2¢
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using rect.inflate()

2008-11-06 Thread W W
On Wed, Nov 5, 2008 at 8:14 PM, John Fouhy [EMAIL PROTECTED] wrote:

 2008/11/6 Christopher Spears [EMAIL PROTECTED]:
  I inserted this code snippet into the Spaceship class:
 
  self.rect = self.image.get_rect()
  print self.rect
  self.rect = self.rect.inflate(-50, -50)
  print self.rect
 
  The following was printed to my console:
  rect0, 0, 70, 53
  rect25, 25, 20, 37
 
  I'm assuming that the first two numbers are coordinates for the upper
 left corner of the rectangle.  The third and fourth numbers are the width
 and height of the rectangle from the upper left corner.  Am I off base here?
  If that is the case, why does rect.inflate() move the upper left corner?


IIRC - in pygame (and some of the other modules) they use a Q4 type
coordinate system. I *think* anyway - it's been a while.

But I believe they work from the top left corner, instead of bottom left. So
your XY rather than (2, 4) moving right and up moves right and down.
Similarly, any manipulations you make will also work from (0,0), rather than
(2, 4) like you might expect.

I'm not 100% sure on that, so you may want to research for a bit just to
either verify or disprove my dim memory  of the possible situation.

HTH,
Wayne




 At a guess: the inflation (or, in this case, deflation) is centred on
 the centre of the figure.  So a horizontal change of -50 means the
 left edge moves 25 pixels right and the right edge moves 25 pixels
 left.  (or, rather, the total width drops frrom 70 pixels to 20
 pixels)

 I'm not sure what's going on with the height, though.

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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Date validation?

2008-11-06 Thread W W
On Thu, Nov 6, 2008 at 1:27 PM, Eric Dorsey [EMAIL PROTECTED] wrote:

 Greetings,I have a program where I ask a user to enter a date in format
 -MM-DD, and get a string like: '2008-10-25'

 Can anyone tell me how I would verify this is a real date before allowing
 it to be passed on to the next part of the program?


I guess it depends on what your definition of real date is... Should the
year fall in a certain range? How about the month and day?

Are you going to require - between each element? Do you know how to split a
string and convert the elements to integers?

That should give you some clues to your solution...
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing an image with pygame.image.load()

2008-11-04 Thread W W
On Mon, Nov 3, 2008 at 8:37 PM, Jerry Hill [EMAIL PROTECTED] wrote:

 Beyond what Bob says about being careful of the escape character ('\')
 and the need to either double it up in a string literal or use a raw
 string, are you sure that path is right?  Usually a drive letter is
 followed by a backslash in windows.  That is, C:\Users\Chris rather
 than C:Users\Chris.


And just FYI, you can use forward slashes, even in windows:

In [50]: cd D:/Program\ Files/
D:\Program Files

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


Re: [Tutor] How to check online status

2008-11-03 Thread W W
On Mon, Nov 3, 2008 at 9:54 AM, Timmie [EMAIL PROTECTED] wrote:

 Dear fellow Pythonistas,
 is it possible to check with Python whether a computer is connected to the
 internet or not?


Yes. That's the short answer anyway.


 I don't not find a module which can do such a thing like 'ping'?


you could use the os module to execute the system command ping


 And how do I make my python scipts that use urllib to recognize the windows
 operating system proxy settings?


I'm not particularly sure, but at first glance
http://www.google.com/search?q=python+urllib+windows+proxy seems to have
some useful looking links.

HTH,
Wayne




 Thanks in advance and kind regards,
 Timmie


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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Iterate by twos

2008-11-02 Thread W W
is there a better/more pythonic way to do something like this?

spam = ['c','c','v','c','v']

for x in xrange(0,5,2):
print spam[x], spam[x+1]

There are other things I'll be doing with the values, but I want to get them
in chunks of two. (I realize that this code will throw errors, it's just a
hasty example of what I need)

Thanks,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Debugging, other

2008-11-01 Thread W W
On Sat, Nov 1, 2008 at 11:21 AM, Jennifer Miller [EMAIL PROTECTED]wrote:

 Hello,

 I would like to step through with debugging in PythonWin, I have added
 this toolbar, but I cannot click on it as an option.  Also, when I
 click run, to define the arguments, do I enter them in the format
 name, name?  Also, when I try to run my code, I get a message at the
 bottom of the screen that says, Failed to run script - syntax error -
 expected an indented block.  I am not sure where I am going wrong here
 - maybe if I could do the debugging, that would help.


It helps to post the exact error message.

For instance:


  File stdin, line 2
print x
^
IndentationError: expected an indented block

came from this entered into the interactive interpreter:

 for x in xrange(1,10):
... print x

Because after a for statement, it expects an indentation. It's considered
standard to indent with four spaces.

My guess is there's something in your code that caused such an error. The
more information you give us, the better we are able to help you.

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


Re: [Tutor] python editor / IDE

2008-10-31 Thread W W
Denis,
You'll find that most editing is subjective - people use what they're
comfortable with.

My recommendation to you, since you love notepad++ and are obviously
comfortable with it; set it as your default editor and install IPython, then
use the %ed magic function to work on your code; or have two windows open;
Notepad++ on one side, IPython on the other, and use the %run magic function
to execute your code.

This is similar to what I do with vi, only if I want to execute (since I
work on *nix) I simply type :!python myfile.py

With IPython, you can use cd just like you would at the command line (and if
you install readlines you can use tab for autocomplete), pwd tells you the
current directory:



In [9]: pwd
Out[9]: 'C:\\Documents and Settings\\Wayne\\Desktop'

In [10]: ls
 Volume in drive C has no label.
 Volume Serial Number is 6082-062C

 Directory of C:\Documents and Settings\Wayne\Desktop
snip
10/31/2008  07:57 AM52 mytest.py
snip

In [11]: %run mytest.py
Hello world!
IPython is a nifty tool!

So, to sum it up - if you want to integrate notepad++ with a python
interpreter, IPython is the way to go!
(Find Ipython here: http://ipython.scipy.org/moin/ )
HTH,
Wayne


On Fri, Oct 31, 2008 at 6:58 AM, spir [EMAIL PROTECTED] wrote:

 Hello,

 I have read tons of reviews of editors for python. But they seem to be all
 biased, meaning that what the author finds important is well documented
 while the rest not at all.
 I'm looking for  something like a simple table showing main features for
 all editors or IDEs. Do you know of anything like that? If not, maybe you
 could point me to editors that meet the following requirements:

 Fondamental features:
 * Written in python (because I plan to tweak inside for some specific
 needs).
 * Use of wxPython for UI (ditto -- I find wx clearer than tk or QT).
 * /Really/ work well with non-ascii systems, including edition of utf-8
 files (most don't in real life use, even when they pretend to).
 * Customizable syntax highlighting.
 * Customizable key bindings.
 * Running of python code from inside the IDE.
 * Code browser at least for currently edited file.
 * Multiple file opening through tabs.
 * Basic editing: search/replace, (un)comment, un(indent),...

 Nice additional features:
 * Additional editing features: tooltips, code expansion, regexps (maybe one
 day I will learn that ;-)),...
 * Project level management/browsing.
 * GUI building (like boa, but boa constantly crashes with non-ascii -- even
 with unicode version of wxPython installed).

 I currently use DrPython which is very well designed for most of this, but
 its lack of code browsing is a pain as soon as a project starts scaling. And
 some of its behaviour is a bit weird for me in some fields (such as edition
 actions on folded or half-folded block).
 Notepad++ is my favorite editor for everything except coding in python. I
 would love to use it, but as far as I know, it lacks integration of a python
 interpretor.

 Thanks,
 Denis

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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mergin two csv files based on a common join

2008-10-31 Thread W W
On Fri, Oct 31, 2008 at 4:04 PM, [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:

 Hello again,
 Thanks for the replies on my previous post, but I have a different
 problem now and don't see how to deal with it in a smooth way.


I'd probably use a dict with a list as the value:


 snip
 1, text, aa
 1, text, xx
 2, text2, something else
 3, text3, something else
 3, text3, zz


this is untested, and it's been a while since I've messed with the CSV
module, but something like this should work, if you split the first file
into 3 lists and the 2nd into two lists:
for col1, col2, col3 in zip(inCol1, inCol2, inCol3):
try:
mydict[(col1, col2)]
mydict[(col1, col2)].append(col3)
except KeyError:
mydict[(col1, col2)] = [col3]

I think that should work.

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterate over multiple objects

2008-10-29 Thread W W
On Wed, Oct 29, 2008 at 5:38 AM, A.T.Hofkamp [EMAIL PROTECTED] wrote:

 snip
 With the zip() function you can merge two sequences into one:

 for x, y in zip(string1, string2):
print x, y


Ah! I *knew* there was a way - I just couldn't remember what it was.

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


[Tutor] Iterate over multiple objects

2008-10-29 Thread W W
Hi,
I'm trying to compare two strings because I want to find the difference.

i.e.
string1 = foobar
string2 = foobzr

is there a simple way to do this with a for loop? This is the method I
tried, but it gives me an error:

In [14]: for x, y in bar[0], bar[1]:
   : print x, y
   :
   :
---
ValueErrorTraceback (most recent call last)

D:\Documents and Settings\Wayne\ipython console in module()

ValueError: too many values to unpack

I suppose I could do:

for x in xrange(0, len(bar[0])):
print bar[0][x], bar[1][x]#yes I realize there's no comparison here,
I know how to do that - this is just a placeholder

Would that be the best/most pythonic solution?

Thanks,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help w/ a for loop

2008-10-24 Thread W W
On Thu, Oct 23, 2008 at 10:29 PM, Monte Milanuk [EMAIL PROTECTED] wrote:

 Hello again, and thanks to all of you who extended your help!
 snipMaybe I'm not clever enough, but I didn't see how either example
 could be used for doing the addition/subtraction determination.  Or rather,
 I found a different way after reading someone else's examples.

snip

#  loop thru n times, summing each pass and switching the sign
 #  on m each time, and printing x every time through.
 for i in range(n):
 x = x + m*(4.0/(i*2+1))
 m = -m


That's probably just as elegant as the way I would have done it; mod
division! :)

 In [50]: for x in range(1, 10):
   : print %d %% 2 =  % (x, ), x % 2
   :
   :
1 % 2 =  1
2 % 2 =  0
3 % 2 =  1
4 % 2 =  0
5 % 2 =  1
6 % 2 =  0
7 % 2 =  1
8 % 2 =  0
9 % 2 =  1

Thus, to adapt it to what you had, declare:
m = -1

And the terms of the loop:
for i in range(1, n+1):
x = x + (m * (i % 2)) * (4.0/(i*2))

At least I'm pretty sure that's syntactically correct. It's 5:47 am and I'm
getting ready for school, so you never know for sure ;)

The great thing about using mod division is that it's /always/ applicable
when you're looking for even/odd status of a number:

In [52]: for x in xrange(-3,3):
   : print %d %% 2 =  % (x, ), x % 2
   :
   :
-3 % 2 =  1
-2 % 2 =  0
-1 % 2 =  1
0 % 2 =  0
1 % 2 =  1
2 % 2 =  0

Yay for mod division! :)

Glad my advice helped!
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] random equation generator

2008-10-23 Thread W W
www.google.com/search?q=pygtk+tutorial
www.google.com/search?q=python+random+generator
www.google.com/search?q=python+dict

If you would like to develop the game, you should first try to develop the
game, and then ask when you get stuck.

If you can't figure out how to get a user to guess between operands '+',
'-', '*', '/' then my guess is you are very new to programming, and this
question shows you are very new to the tutor list. We're happy to help you
find a solution when you get stuck, but we won't write your program for you.
If you're stuck at the planning phase it seems that you may be trying to
tackle a subject that's a little too deep, and you'll find a lot of
difficulty in learning pyGTK.

Here are some assignments for you. Successfully completing these will not
only show that you're willing to learn and take advice, but they will also
help you in your quest to write your game.

tip: search google for the functions you should use, if you don't already
know them. Using the keyword python before the functionality will help
narrow your results.

1) Write a progam that will generate 10 random numbers in a /range/ of 0-3,
and print each one out.
After you do this, allow the user to /input/ the number of numbers (i.e. 5
instead of 10)
sample output:
Random Numbers:
0
3
1
2
0
0
2
1
3
1

Please enter a number: 4
0
1
3
1

2) Write a program that allows the user to input a number 0-3, and
determines which operand to print.
Sample output:

Enter a number: 0
Operand: +

Enter a number: 1
Operand: -

Enter a number: 3
Operand: /

Enter a number: 2
Operand: *

Do these things and you'll be well on your way to writing your program!
(also, feel free to use http://pastebin.com to post your code to report on
your progress)

Good luck!
HTH,
Wayne

If and only if you get stuck should you read this!

Seriously! Stop reading here! :)

Tip: Once you have searched google and the python docs for raw_input, while
loop, dict, list, if else, random and read all the documentation you can
find, if you cannot figure out the solution, only then should you ask
another question, and only about the topic on which you can't figure out on
your own!

On Thu, Oct 23, 2008 at 5:12 AM, i i [EMAIL PROTECTED] wrote:

 hi, can u tell me any good tutorial site for pygtk, any that contains
 detail explanation of pygtk.
 i want to develop a game,that will randomly generate the operands,and the
 answer,a user have to chosse from the operators(+,-,*,/).
 which function should i use to randomly generate equation.

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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help w/ a for loop

2008-10-23 Thread W W
On Wed, Oct 22, 2008 at 11:09 PM, Monte Milanuk [EMAIL PROTECTED] wrote:

 Hello all,

 New guy here, so go easy on me ;)


Welcome to python and the tutor list!


 I'm starting to work my way through Python Programming by Zelle, and have
 hit a bit of a wall on one of the programming exercises in Chapter 3 (#15 if
 anyone has the book handy).

 What the question ask is:  Write a program that approimates the value of pi
 by summing the terms of this series: 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11+...
 The program should ask the user for 'n', the number of terms to sum, and
 then output the sum of the first 'n' terms of this series.

 Where I am running into problems is how to do the '-'  '+', depending on
 the value of 'n'.  i.e. if 'n' = 3, it's going to be a -  an +, if 'n' =5
 its going to be -, +, -, +, etc.  How to make that work in terms of an
 algorithm is making my head hurt (and its so early in the book yet... ;) )


Here's a suggestion: look at only the value of the denominator (as the top
is obviously constant at 4, for the sake of pattern searching you only need
to worry about the variable) -

1 - 3 + 5 - 7 + 9 - 11 + ...

Do you notice a pattern? (if it doesn't pop out, read on...)





1+2 = ?
1+4 = ?
1+6 = ?
1+8 = ?
1+10 = ?

If you want a fairly easy way to figure out whether it should be + or -,
take another look at the pattern.

If you need a hint, read past my name.

HTH,
Wayne

Hint: Think of the pattern in terms of relation to 2


WAIT!
Don't read beyond here if you want to discover the solution yourself!




2/2 = 1
4/2 = 2
6/2 = 3
8/2 = 4
etc.


 Here's what I have thus far:

 #   approximate_pi.py
 #   Approximates the value of 'pi' by summing the terms of a series.
 #

 import math

 def main():
 print This program will approximate the value of pi
 print to a degree determined by the user. 
 print

 #  get the value of n from the user
 n = input(How many terms do you want me to sum?  )
 print

 #  create a loop from 1 to n+1, odd)
 for i in range(1,n + 1,2):
 #  each term is '4/i' as it steps thru the loop starting with 1
 x = 4 / i
 #  not sure where to go from here


 print
 #  output the sum - convert it to a float just in case
 print The sum of the numbers you entered is, (float(sum))

 #  calculate the difference between our approximation and Python's pi
 diff = sum - math.pi

 #  output the difference
 print
 print The difference between your 'pi'  Python's pi is, diff, .



 main()


 Any assistance or nudges in the right direction would be most appreciated.

 Thanks,

 Monte

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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread W W
On Mon, Oct 20, 2008 at 3:13 AM, Alan Gauld [EMAIL PROTECTED]wrote:

 Chris Fuller [EMAIL PROTECTED] wrote

  want to clear the screen, printing the control sequence ESC[2J is all you
 need.

  print chr(0x1b) + '[2J'


I don't know if this is the most graceful solution... but it seems to work:
import os

if os.system('cls') == 0:
pass
elif os.system('clear') == 0:
pass
else:
print 'No clear command available'

That should take care of most of your OS' out there...

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  1   2   3   >