Re: [Tutor] How do I make Python draw?

2005-07-27 Thread luke

> Thanks. Will ask if I have any more questions. Maybe I won't have to go to
> Visual Basic to write my games. Maybe Python will do the trick.
Oh my god.
Don't ever compare Python to Basic on a python mailing list.
You'll get eaten alive ;-)

Seriously though,
If you take the time to learn PyGame, it's about the easiest and
best way to write a game in any language (from scratch that is.)
I highly recommend it.
In fact I'm writing a PyGame game right now.
If you're interested in seeing the source at some point,
Just ask.
Although I won't send it just yet because it has no drawing code ATM.
Just game logic.

Hope ThAt HeLPs.
Don't ever resort to Visual Basic.
If you think something would be easier in VB then ask us
and we will tell you how to do it in Python.
VB is not a good language to learn because it
is the complete opposite of every other programming language.

I really can't think of a reason to use VB over Python, C++ or Java.

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


Re: [Tutor] OT: we won't eat VB programmers for lunch [Was: How do I make Python draw?]

2005-07-27 Thread luke
hehe.
<3 malbolge.

Yeah, I actually learned basic as my first language...
I don't mind it.
I just don't like it all that much.

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


Re: [Tutor] learning classes (kinda long)

2005-07-30 Thread luke
hello.

I didn't read or understand your code that well.
but you asked:

> for section in config.sections():
> section = bsserver.Server() 
> 
> first I would like for this instance to be named the name of the host in
> the section
> but i keep getting instances named section I think doing it may require
> something more complex than my current understanding. How do I get them
> to become individuallly named
> Instances?

did you think about using a dictionary?
example that might apply:
#start of code


class aclass:
def __init__(self,astring):
self.avar = astring+"!!!"

listofstrings = ["hello","hi","what's up"]
classesdict = {}
for item in listofstrings:
classesdict[item] = aclass(item)

print classesdict["hello"].avar
#should print "hello!!!"


print classesdict["hi"].avar
#should print "hi!!!"


print classesdict["what's up"].avar
#should print "what's up!!!"


#end of code
I hope that helps ya.
-Luke

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


Re: [Tutor] substitute function

2005-07-31 Thread luke
Are you making a biology program Srinivas?

- Original Message -
From: "Kent Johnson" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, July 31, 2005 2:46 PM
Subject: Re: [Tutor] substitute function


> Srinivas Iyyer wrote:
> > Hello group:
> >
> > Is there a 'substitute' function in python.
> >
> > For example:
> > I want to substitute A with T and G with C and vice
> > versa
> >
> > A -> T
> > G -> C
> > T -> A
> > c -> G
>
> You can do this with the translate() method of a string. It is a two-step
process. First you have to make a translation table that defines the
translation. Do this with string.maketrans():
>  >>> import string
>  >>> xlate = string.maketrans('AGTC', 'TCAG')
>
> Next use the translation table to translate the string of interest:
>  >>> 'AAGTTC'.translate(xlate)
> 'TTCAAG'
>
> Kent
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Help with file I/O.

2005-07-31 Thread luke
Nathan,

I saw in your previous example that you called
#quote
file = raw_input("File name please: ")
f = file(file, "r")
for line in f.readlines():
print line
f.close()
#endquote

the reason you were getting an error is that
you made a variable named "file" on line one,
which then overwrote the builtin method
"file" in your namespace.
therefore, the compiler throws a
"string not callable error"
because it's trying to call "File name please: "(file, "r")
which of course doesn't work.

What you want to do is make __sure__
that you never name a variable the same thing as a function
unless you're sure that's what you want to do.
I believe some poeple recommend that you use
nouns for variables (because they're things)
and verbs for functions (because it's an action)
but in this case,
just make sure not to use "file"
or "open" or "str" or "int" or anything as variable names.

as for your other question,

> Okay I understand how to open and read to a file, but how do I write to a
> file, e.g. a list.

you should really read the tutorial and try to figure it out before asking
us.
I am going to give you the answer but don't keep reading if you want to
figure it out yourself.

def WriteToFile(listoflines,filename="default.txt"):
  f = file(filename, "w")
  f.writelines(listoflines)
  f.close()

def main(args):
  text = ["hello\r\n","Good Morning nathan.\r\n"]
  filename = ""
  for arg in args:
if arg == "-f" or arg == "--filename":
  grab_next_arg = 1
  continue
if grab_next_arg:
  filename = arg
  break

  if filename != "":
WriteToFile(text,filename)
  else:
WriteToFile(text)

hope that helps.
-Luke

> - Original Message -
> From: "Nathan Pinno" <[EMAIL PROTECTED]>
> To: "Nathan Pinno" <[EMAIL PROTECTED]>; "Danny Yoo"
> <[EMAIL PROTECTED]>
> Cc: 
> Sent: Sunday, July 31, 2005 2:46 PM
> Subject: Re: [Tutor] Help with file I/O.
>
>
> > Here's the improved version.
> > file = raw_input("File name please: ")
> > f = open(file)
> > for line in f.readlines():
> >print line
> > f.close()
> >
> > - Original Message -
> > From: "Nathan Pinno" <[EMAIL PROTECTED]>
> > To: "Danny Yoo" <[EMAIL PROTECTED]>
> > Cc: 
> > Sent: Sunday, July 31, 2005 2:29 PM
> > Subject: Re: [Tutor] Help with file I/O.
> >
> >
> >> Here's my work. I call it filewriter.
> >> The code:
> >> file = raw_input("File name please: ")
> >> f = file(file, "r")
> >> for line in f.readlines():
> >>print line
> >> f.close()
> >>
> >> Will it do the trick?
> >>
> >> Nathan
> >> - Original Message -
> >> From: "Danny Yoo" <[EMAIL PROTECTED]>
> >> To: "Nathan Pinno" <[EMAIL PROTECTED]>
> >> Cc: 
> >> Sent: Sunday, July 31, 2005 12:22 AM
> >> Subject: Re: [Tutor] Help with file I/O.
> >>
> >>
> >>>
> >>>
> >>> On Sun, 31 Jul 2005, Nathan Pinno wrote:
> >>>
> >>>> Well, you saw my password program. That was my first attempt at using
> >>>> file I/O. Thought I'd try it big time. You saw where that went.
> >>>
> >>> Ok, let's take a look.  It was from this message, right?
> >>>
> >>>http://mail.python.org/pipermail/tutor/2005-July/039478.html
> >>>
> >>> That was such a while back that I think you probably learned a lot
since
> >>> then, and I think a few of the issues there were less about I/O and
more
> >>> about just general programming.
> >>>
> >>> Let's try a few things, just to see why you're getting stuck.  Can you
> >>> write a program that reads in a file, and just prints all of its lines
> >>> out
> >>> to screen?
> >>>
> >>>
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] What's the invaild syntax? Error message and relative codesupplied.

2005-07-31 Thread luke
NATHAN!
you have had this exact same problem yesterday!
cmon man.
If you see an invalid syntax error,
look on the preceeding line.
it's usually caused by not enough parenthesis for your function call.
so we scroll down to lines 64-66...

>which = 1234
>while which != -1:
>which = int(raw_input("Change which Grade: ")
tada there's our error.
you forgot an extra parenthesis.
however many (( you have on a line you need ot have the same number of )) on
the line.
which = int(raw_input("Change which Grade: ")
becomes
which = int(raw_input("Change which Grade: "))

HTH,
-Luke

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


[Tutor] deck dealing program

2005-08-07 Thread luke



from random import randint
 
def identify_card(n):    
cardname = ""    royals = 
["Jack","Queen","King","Ace"]    temp = n % 
13    if temp > 
8:    cardname += 
royals[temp-9]    
else:    cardname += 
str(temp+2)    cardname += " of "
 
    suits = 
["Spades","Hearts","Diamonds","Clubs"]    cardname += 
suits[n/13]    return cardname
 
def main():    deck = 
range(52)
    cards = []
    while 
1:    x = raw_input("how many cards 
do you want? ")    
try:    x = 
int(x)    except 
ValueError:    
print "Invalid value exiting for I have no error code. Please use an int next 
time."    
raise SystemExit    if x <= 52 and 
x >= 0:    
y = 0    
while y < 
x:cards.append(identify_card(deck.pop(randint(0,len(deck)-1    
y += 1    
break
    print cards
if __name__ == "__main__":    
main()
 
#Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] deck dealing program

2005-08-08 Thread luke
Just offering my take on the problem.
hope it helps someone.
- Original Message -
From: <[EMAIL PROTECTED]>
To: 
Sent: Monday, August 08, 2005 2:02 AM
Subject: Re: [Tutor] deck dealing program


> Are you:
>   a.) Having trouble with the code and looking for help?
>   b.) Looking for suggestions on how to improve the code?
>   c.) Offering the code as a demo for Nathan et al.?
>
> I was just doing stuff along the same lines and was having fun seeing the
> different approaches to the same problem.
>
> --Todd
>
> On Monday 08 August 2005 02:38 am, luke wrote:
> > from random import randint
> >
> > def identify_card(n):
> > cardname = ""
> > royals = ["Jack","Queen","King","Ace"]
> > temp = n % 13
> > if temp > 8:
> > cardname += royals[temp-9]
> > else:
> > cardname += str(temp+2)
> > cardname += " of "
> >
> > suits = ["Spades","Hearts","Diamonds","Clubs"]
> > cardname += suits[n/13]
> > return cardname
> >
> > def main():
> > deck = range(52)
> > cards = []
> > while 1:
> > x = raw_input("how many cards do you want? ")
> > try:
> > x = int(x)
> > except ValueError:
> > print "Invalid value exiting for I have no error code.
Please
> > use an int next time." raise SystemExit
> > if x <= 52 and x >= 0:
> > y = 0
> > while y < x:
> >
> > cards.append(identify_card(deck.pop(randint(0,len(deck)-1 y += 1
> > break
> > print cards
> > if __name__ == "__main__":
> > main()
> >
> > #Luke
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Question on listing cards, then deleting one or more items by user's choice.

2005-08-09 Thread luke
>Say I deal 5 cards, and then list them. How would I print the list of
cards, with the numbers >of each card(the position in the list)? Then delete
a certain card or cards, based upon the >user's choice?.

hope this points you in the right direction Nathan.
-Luke


#start of program
#--
alist = ["1","2","3","4","5"]
avar = ''
while 1:
 if len(alist) == 0:
  break
 for item in range(len(alist)):
  print "item at list index ", item, " == ", alist[item]
 avar = raw_input("type -1 to exit or type the index of the item  you want
to remove ")
 try:
  avar = int(avar)
  if avar == -1:
   break
  elif avar > len(alist):
   print "oops error. indexOutOfRange"
  else:
   del(alist[avar])
 except ValueError:
  print "oops error. please enter an integer value."
#--


And the output:
#
item at list index  0  ==  1
item at list index  1  ==  2
item at list index  2  ==  3
item at list index  3  ==  4
item at list index  4  ==  5
type -1 to exit or type the index of the item  you want to remove 0
item at list index  0  ==  2
item at list index  1  ==  3
item at list index  2  ==  4
item at list index  3  ==  5
type -1 to exit or type the index of the item  you want to remove 3
item at list index  0  ==  2
item at list index  1  ==  3
item at list index  2  ==  4
type -1 to exit or type the index of the item  you want to remove 2
item at list index  0  ==  2
item at list index  1  ==  3
type -1 to exit or type the index of the item  you want to remove 0
item at list index  0  ==  3
type -1 to exit or type the index of the item  you want to remove -1





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


Re: [Tutor] Would like some help

2005-08-15 Thread luke
Howard,
I believe what's happening in the second example is that you can combine
dictionaries.
...
>>>d2 = {'hello':1,'hi':2}
>>>print d2.items()
[('hi',2),('hello',1)]

so in the second example you can just pass it a list of elements (.items())
and it will concatenate (append?) these to the new dictionary.
hope that helps.

Luke


- Original Message -
From: "Howard Kao" <[EMAIL PROTECTED]>
To: 
Sent: Monday, August 15, 2005 6:32 AM
Subject: [Tutor] Would like some help


> Directly Quoted From the Python Cookbook
> 1.3 Constructing a Dictionary Without Excessive Quoting
> Credit: Brent Burley
>
> 1.3.1 Problem
> You'd like to construct a dictionary without having to quote the keys.
>
> 1.3.2 Solution
> Once you get into the swing of Python, you may find yourself
> constructing a lot of dictionaries. However, the standard way, also
> known as a dictionary display, is just a smidgeon more cluttered than
> you might like, due to the need to quote the keys. For example:
>
> data = { 'red' : 1, 'green' : 2, 'blue' : 3 }
> When the keys are identifiers, there's a cleaner way:
>
> def makedict(**kwargs):
> return kwargs
> data = makedict(red=1, green=2, blue=3)
> You might also choose to forego some simplicity to gain more power.
> For example:
>
> def dodict(*args, **kwds):
> d = {}
> for k, v in args: d[k] = v
> d.update(kwds)
> return d
> tada = dodict(*data.items(  ), yellow=2, green=4)
> End Quote
>
> Hi guys,
> Above is a direct cut & paste from the book (hope I am not violating
> any thing...).  I've read the Python docs and can understand the first
> def example ok, I suppose.  However I would like some detailed
> explaination about the second example, the dodict one.  How exactly
> does it work?  It just puzzles me why this would be more powerful or
> better, even though I can understand and agree that re-writting
> programs makes good practice.  In fact that's what I am looking for
> from reading this book.  Just hope someone can walk me through this
> simple code.  Thanks for the help.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] How can I make this run right?

2005-08-15 Thread luke

> I put in a 4 and expected 24, and instead got 12. It is supposed to give
4!
> not 4*3.
[snip rest of message]

nathan
your problem is easy to see...
> >> n = int(raw_input("Number: "))
> >> x = n-1
> >> while 1:
> >>t = n*x
> >>while x > 1:
> >>x -= 1
> >>else:
> >>break
> >> print t

think about it for a *while*...
Hint *while*
hint hint *change the while*
hint hint hint *the inner while*

nathan I see that you want to do n!(factorial)
but when you explained it you just said you wanted number!
which is confusing because I think everyone thought you were just excited.
you could always use a recursive function for factorial, IE.

def factorial(n):
 if n > 1:
  return factorial(n-1) * n
 else:
  return n

HTH,
Luke
P.S. Try to fix yours it'll help you.  tell me if you get it working
correctly.

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


Re: [Tutor] convert a file from plaintext(Ascii) to unicode? very quickquestions

2005-08-15 Thread luke
um...
>>> help(unicode)
Help on class unicode in module __builtin__:
[snip help stuff]
 |  encode(...)
 |  S.encode([encoding[,errors]]) -> string or unicode
 |
 |  Encodes S using the codec registered for encoding. encoding defaults
 |  to the default encoding. errors may be given to set a different
error
 |  handling scheme. Default is 'strict' meaning that encoding errors
raise
 |  a UnicodeEncodeError. Other possible values are 'ignore', 'replace'
and
 |  'xmlcharrefreplace' as well as any other name registered with
 |  codecs.register_error that can handle UnicodeEncodeErrors.

[snip rest of help]

Denise,
I dont know much about Unicode but it seems like
f = file(filename, "r")
text = f.readlines()
text = text.encode()
#or maybe just text.encode()?
f.close()

should encode the filetext to unicode.
then you could do a
f = file(filename, "w")
f.writelines(text)
f.close()

sorry I don't know more about it but I hope that helps you.
-Luke
- Original Message -
From: "D. Hartley" <[EMAIL PROTECTED]>
To: "Python tutor" 
Sent: Monday, August 15, 2005 7:49 PM
Subject: [Tutor] convert a file from plaintext(Ascii) to unicode? very
quickquestions


> Hello guys!
>
> Is there a way to convert a file from plaintext(Ascii) to unicode?  I
> have found all my notes about moving between hex., int's, chr's,
> ord's, etc, but all of these things were only riddle exercises to me
> and I have a hard time keeping them straight.  I'm pretty sure I knew
> the answer to this and now cannot find it anywhere (even googling
> through my old tutor posts!)
>
> Does anyone have a quick answer/pointer?
>
> Thanks so much!
>
> ~Denise
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] convert a file from plaintext(Ascii) to unicode? very quickquestions

2005-08-15 Thread luke
List:
I'm forwarding this private message(hope you don't mind Denise)
I personally have no idea what to do, but
someone else might be able to help.
-Luke


- Forwarded Message -

text is a list, so you can't encode it.  but you can iterate over each
of the elements and encode them.  I have tried several variations of
that, but keep ending up with all my newlines being little boxes. any
ideas?

Thanks,
Denise

On 8/15/05, luke <[EMAIL PROTECTED]> wrote:
> um...
> >>> help(unicode)
> Help on class unicode in module __builtin__:
> [snip help stuff]
>  |  encode(...)
>  |  S.encode([encoding[,errors]]) -> string or unicode
>  |
>  |  Encodes S using the codec registered for encoding. encoding
defaults
>  |  to the default encoding. errors may be given to set a different
> error
>  |  handling scheme. Default is 'strict' meaning that encoding errors
> raise
>  |  a UnicodeEncodeError. Other possible values are 'ignore',
'replace'
> and
>  |  'xmlcharrefreplace' as well as any other name registered with
>  |  codecs.register_error that can handle UnicodeEncodeErrors.
>
> [snip rest of help]
>
> Denise,
> I dont know much about Unicode but it seems like
> f = file(filename, "r")
> text = f.readlines()
> text = text.encode()
> #or maybe just text.encode()?
> f.close()
>
> should encode the filetext to unicode.
> then you could do a
> f = file(filename, "w")
> f.writelines(text)
> f.close()
>
> sorry I don't know more about it but I hope that helps you.
> -Luke
> - Original Message -
> From: "D. Hartley" <[EMAIL PROTECTED]>
> To: "Python tutor" 
> Sent: Monday, August 15, 2005 7:49 PM
> Subject: [Tutor] convert a file from plaintext(Ascii) to unicode? very
> quickquestions
>
>
> > Hello guys!
> >
> > Is there a way to convert a file from plaintext(Ascii) to unicode?  I
> > have found all my notes about moving between hex., int's, chr's,
> > ord's, etc, but all of these things were only riddle exercises to me
> > and I have a hard time keeping them straight.  I'm pretty sure I knew
> > the answer to this and now cannot find it anywhere (even googling
> > through my old tutor posts!)
> >
> > Does anyone have a quick answer/pointer?
> >
> > Thanks so much!
> >
> > ~Denise
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

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


Re: [Tutor] no rsplit

2005-08-22 Thread luke

>v = "64x43x12"  -> '64x43', '12'
> 
> How split it by the las 'x'?
[snip]

>>>v = "64x43x12"
>>>temp = v.split("x")[-1:]
>>>print temp
['12']

that's the best I can do for now.
HTH,
-Luke

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


Re: [Tutor] Split a string into characters

2005-08-22 Thread luke
>   How do I split a string like "Hans" into a list of characters
> ['H','a','n','s']?
[snip]

well you could write your own function...

def splititems(itemlist):
templist = []
for item in itemlist:
templist.append(item)
return templist

print splititems("Hello")

or even

def splititems(itemlist):
return [item for item in itemlist]

print splititems("Hello")

well I have to go, I hope that helps you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Game Engine HowTos?

2005-09-05 Thread luke
>>I believe this is what you are looking for:
>>http://www.pygame.org/
>>
> Pygame? Well I'll take a look... do they have documentation for Game
> Engine writing?

why didn't you look before you asked? just curious.
Pygame is a library that gives you easy, low-level access to the graphics 
buffer
and the sound as well.
it has commands for blitting images and drawing primitive shapes on the 
screen.
so it isn't a game engine.
it's what goes under the game engine, doing all the dirty drawing work for 
you.

I don't think there are game engine tutorials on the site explicitly,
but you should be able to figure out how to write one if you look through 
the
other tutorials.
also, you might want to look into joining the pygame mailing list.
they are very helpful.
-Luke

Afterthought:
This e-mail was entirely pointless I apologize but I am sending it anyway
because I wasted my time writing it. 

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


Re: [Tutor] Newbie Just Joining

2010-01-11 Thread Luke Paireepinart
Hey, welcome to the list! No probemas so far?

On 1/11/10, Kamron Bennett  wrote:
> I'd like to say hi and I'm a new member of this mailing list.
>
> --
> "You'll never know if you don't go, you'll never shine if you don't glow"
> -Smash Mouth "All Star"
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help in python

2010-01-21 Thread Luke Paireepinart
Don't post messages to the list in reply to other messages, it messes up
threading.
Other than that, you'll have to tell us more about your assignment if you
want help.
-Luke

On Thu, Jan 21, 2010 at 11:48 AM, invincible patriot <
invincible_patr...@hotmail.com> wrote:

>  hi
> I am a student and i need soe help regarding my assignmentif some one can
> help me il be glad.
>
> i wil be waiting for the reply
>
> thanks
>
>
>
> --
> Date: Thu, 21 Jan 2010 12:33:40 -0500
> From: samueldechampl...@gmail.com
> To: tutor@python.org
> Subject: [Tutor] Hello
>
> This is my first message to this mailing list.
> I want to create a project with glade and pygtk on fedora.
> Can you suggest a good IDE?
>
> --
> Hotmail: Trusted email with powerful SPAM protection. Sign up 
> now.<http://clk.atdmt.com/GBL/go/196390707/direct/01/>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: length of a string? Advice saught

2010-01-27 Thread Luke Paireepinart
-- Forwarded message --
From: Luke Paireepinart 
Date: Wed, 27 Jan 2010 18:01:35 -0600
Subject: Re: [Tutor] length of a string? Advice saught
To: Kirk Z Bailey 

Are you using the post or the get method to submit the form? That's
likely your problem. Strings in Python are only limited by your memory
and your program will crash with a memoryerror exception if that's the
problem you're running into (doubtful for user-entered txt unless your
server only has 1k of ram or something.)

On 1/27/10, Kirk Z Bailey  wrote:
> I wrote a program to let me edit web-pages without bothering with
> ftp; it loads up a simple form with the page guts in it, and
> saves it through another script. Until yesterday, EditMyPage
> worked fine. Alas, I had a rather long winded page and it
> truncated it- completely omitted the last 1/4 of the original
> file, creating big problems. Looking everything over, I can only
> conclude that somehow python 2.23 (ok, it's an old server; shoot
> me, I'm poor) has a limit on a simple string variable. Can I
> declare the variable as a long winded version and save the
> trouble, or do AI need a witchdoctor here?
>
> --
> end
>
> Very Truly yours,
>   - Kirk Bailey,
> Largo Florida
>
> kniht
>+-+
>| BOX |
>+-+
> think
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I love python

2010-01-28 Thread Luke Paireepinart
Glad you like it.  I do too.  I'm taking a graduate course "Crafting
Compilers" and my prof. said I could use Python to write my compiler.  It'll
be the first one for his class that wasn't written in C/C++.

On Thu, Jan 28, 2010 at 10:53 AM, Samuel de Champlain <
samueldechampl...@gmail.com> wrote:

> I am presently doing the "Dive into Python tutorial", and I wanted to share
> these lines with you.
>
> "As a former philosophy major, it disturbs me to think that things
> disappear when no one is looking at them, but that's exactly what happens in
> Python. In general, you can simply forget about memory management and let
> Python clean up after you. " - Mark Pilgrim
>
> I love python.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I love python

2010-01-28 Thread Luke Paireepinart
Yeah, I'm really excited.  The graduate school teachers are much more
willing to let me use Python than the undergrads were.  I'm also doing my
Internet Information Processing course using Python, as well as my Data
Mining one. :)

On Thu, Jan 28, 2010 at 1:12 PM, Shashwat Anand wrote:

> Whoaa...even me too have Compilers as a graduate course this sem, (lex,
> flex, yacc stuff) but the labs  have not started yet. Will see how much
> pythonic I can make this lab :D
>
>
> On Fri, Jan 29, 2010 at 12:36 AM, Luke Paireepinart <
> rabidpoob...@gmail.com> wrote:
>
>> Glad you like it.  I do too.  I'm taking a graduate course "Crafting
>> Compilers" and my prof. said I could use Python to write my compiler.  It'll
>> be the first one for his class that wasn't written in C/C++.
>>
>> On Thu, Jan 28, 2010 at 10:53 AM, Samuel de Champlain <
>> samueldechampl...@gmail.com> wrote:
>>
>>> I am presently doing the "Dive into Python tutorial", and I wanted to
>>> share these lines with you.
>>>
>>> "As a former philosophy major, it disturbs me to think that things
>>> disappear when no one is looking at them, but that's exactly what happens in
>>> Python. In general, you can simply forget about memory management and
>>> let Python clean up after you. " - Mark Pilgrim
>>>
>>> I love python.
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] can any one help

2010-01-30 Thread Luke Paireepinart
On Sat, Jan 30, 2010 at 5:40 PM, Grigor Kolev wrote:

> Excuse me but I have question too.
> Why when i write this function in python shell not work says
> SyntaxError: invalid syntax
> but when I use IDLE make endless loop
>
Your tabbing is probably messed up or something.

You guys both need to be a lot more clear with your questions.
If it doesn't seem like you put in the effort for a proper post then you're
unlikely to get a proper reply.

-Luke


> Sorry I also teach Python.
> > def fibn(n):
> > a,b=15,2
> > while a>n:
> > print a, # it is same like print a, a, b = a, a+b
> > You can not print this. SyntaxError: invalid syntax
> > a,b=a,a+b
> > fibn(-1)
> --
> Grigor Kolev 
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me

2010-01-30 Thread Luke Paireepinart
[snip homework]

>
>
> please help me
>
>
This is a tutor mailing list.  Tutor means we will help you learn, not that
we will write your homework assignments for you for free.  That is the
opposite of learning.

Try all of the programs.  Give us what you have tried and what didn't work,
why you thought it would work, why you think it didn't work, and anything
else helpful (eg. if you get an error message include the whole traceback,
don't paraphrase it.)

In other words, if you don't have code that you've tried and a specific
problem you're having, you're not going to get a reply.  We're busy people,
make it easy for us to help you.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem creating a search

2010-01-30 Thread Luke Paireepinart
On Sat, Jan 30, 2010 at 4:42 PM, Shashwat Anand wrote:

>
>
> On Sun, Jan 31, 2010 at 3:47 AM, jim serson wrote:
>
>>  Hi I am pretty new to python and programming in general. I am trying to
>> create a search that takes a user input for a file location and user input
>> to find a group of numbers or a phrase in that file count how many times it
>> appears then display it.
>>
>> I have gone through a tutorials and searched I/O to find the code I need.
>> Although I have not been able to make it work properly yet.
>>
>> I am able to open and read from the file the user would input but cant
>> seem to make the other input retrieve the numbers or phrase from the file or
>> have it count how many time it appears. If anyone can help or point me in
>> the right direction I would appreciate it. Thanks for your time.
>>
>> look_in = raw_input ("Enter the search file to look in ")
>> search = raw_input ("Enter your search item ")
>>
>c = open(look_in, "r").read().count(search)
>print c
>if c:print search, "your search was found"
>else:print "your search was not found"
>
> As Anand pointed out, in Python if you have a problem that you would think
would have a common (/ simple) solution, it probably does.  In this case you
can just read the whole file into a string and use a string method to count
the occurrences.  The disadvantage is that the file is then residing
completely in memory, which may not be ideal for larger files.  So in that
case you'll have to iterate over the file line-by-line, but you can still
use the count method to determine how many times an item occurs in each
line.
For example you could easily do something like this:

infile = raw_input("Input file: ")
search = raw_input("search term: ")
count = 0
for line in infile:
count += line.count(search)


The key here is the "for line in infile" will not keep the whole file in
memory (at least I don't think it will, I believe that it's a generator so
it's yielding each line).  It probably will run more slowly than Anand's
solution, though.  Depends on your requirements.


Good luck with Python and hopefully we can help you with any other stumbling
blocks you might encounter while learning this wonderful language :)
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] please help me

2010-01-31 Thread Luke Paireepinart
Please reply on-list unless you really need to speak to me off-list.
Use "reply-all" to reply to everyone.

Tutor doesn't work in that you get one of us as a tutor and we help you with
every problem you have.  For this mailing list you e-mail us a specific
problem and everyone collaborates to guide you through it.  When we say
"specific problem" we mean "you have coded a solution that looks to you like
it would work but it doesn't and you're stuck" and then we'll help you
figure out why you're stuck and what you need to do to fix the program.

(P.S. Sorry for the top-post, I'm not sure how to reply in-line to a
forwarded message.)


-- Forwarded message --
From: invincible patriot 
Date: Sun, Jan 31, 2010 at 4:05 AM
Subject: RE: [Tutor] please help me
To: rabidpoob...@gmail.com


 m sorry but i am not asking u to solve these for me rather i send all the
questions to u just to let u know what i want to do n now i m looking
froward for ur guidance so that i can write programme for thhem
i think itz fair enough to ask what should i do, but i am not asking u to
solve them for me
m just looking forward for some help


--
From: rabidpoob...@gmail.com
Date: Sat, 30 Jan 2010 19:39:05 -0600
Subject: Re: [Tutor] please help me
To: invincible_patr...@hotmail.com
CC: tutor@python.org


[snip homework]



please help me


This is a tutor mailing list.  Tutor means we will help you learn, not that
we will write your homework assignments for you for free.  That is the
opposite of learning.

Try all of the programs.  Give us what you have tried and what didn't work,
why you thought it would work, why you think it didn't work, and anything
else helpful (eg. if you get an error message include the whole traceback,
don't paraphrase it.)

In other words, if you don't have code that you've tried and a specific
problem you're having, you're not going to get a reply.  We're busy people,
make it easy for us to help you.

-Luke


--
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up
now.<http://clk.atdmt.com/GBL/go/196390709/direct/01/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python and sqlite

2010-01-31 Thread Luke Paireepinart
Yes, it works fine with sqlite.  I've seen very large projects use it just
fine.
I'd recommend googling "pysqlite" or something similar.
-Luke

On Sun, Jan 31, 2010 at 11:03 AM, Samuel de Champlain <
samueldechampl...@gmail.com> wrote:

> My project is relatively light and postgresql or mysql might be overkill.
> Does python work well with sqlite?
> If so, can you point me towards the proper libraries and manuals/tutorials?
> Thanks.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] can any one help

2010-01-31 Thread Luke Paireepinart
On Sun, Jan 31, 2010 at 3:27 PM, invincible patriot <
invincible_patr...@hotmail.com> wrote:

>  thanks for the reply
> i did one question
> i will tel u my progress in another question n then u tel me that what next
> must be done
>
> thanks
>
> Write a small Python program that generates the list of all pairs of
> characters c and
> its doubling 2 c, where c moves through all the letters of the string
> "foobar" and prints it out.
> The result will look like:
> [(’f’, ’ff’), (’o’, ’oo’), (’o’, ’oo’), (’b’, ’bb’), (’a’, ’aa’), (’r’,
> ’rr’)]
>
> thatz the question
> i think that first i woulf take a string 'foobar'
> convert it into a list
> take itz length
> n then do indexing
> and then multiply using for loop
>
> herez my code
>
> a='foobar'
> b=list(a)
> print b
>
> ['f','o','o','b','a','r']
>
> c=len(b)
> 6
>
>
> thatz where i am
> now i wana do the indexing of each character so that i use for loop n
> multply each character with 2
>
>
See now that you have provided us with what you've tried we can help you a
little more.
How do you think you should do the multiplication?  You mentioned a 'for
loop' but you didn't actually try using one in your code.

Also one hint, strings can be used directly in this situation.
as an example,
a = 'foobar'
len(a)
6

You don't actually have to convert it to a list before iterating over it.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
You want to promote one of your variables to float before you do the
calculation, this will make all other variables automatically cast. So
(float(y2) - y1) / (x2-x1).  if you do the float cast after the
calculation, you will do the calculation as integers and so even
though you'll get "2.0" you won't ever be able to get "2.2" for
example.

On 2/5/10, Antonio de la Fuente  wrote:
> Hi all,
>
> I'm trying to do exercises from:
>
> http://openbookproject.net/thinkcs/python/english2e/ch05.html
>
> exercise number 3 (slope function) and when I run it:
>
> python ch05.py -v
>
> the doctest for the slope function failed, because is expecting a
> floating point value and not an integer:
>
> Failed example:
> slope(2, 4, 1, 2)
> Expected:
> 2.0
> Got:
> 2
>
> This is the function, and how I modified so it would return a floating
> point value (multiply by 1.0). But this doesn't feel the right way to
> do things, or is it?
>
> def slope(x1, y1, x2, y2):
> """
> >>> slope(5, 3, 4, 2)
> 1.0
> >>> slope(1, 2, 3, 2)
> 0.0
> >>> slope(1, 2, 3, 3)
> 0.5
> >>> slope(2, 4, 1, 2)
> 2.0
> """
> result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
> return result_slope
>
> Another question is, anybody knows if these questions from this online
> book are answered somewhere? I can't manage to find them?
>
> Thank you for your time.
> Antonio.
>
> --
> -
> Antonio de la Fuente Martínez
> E-mail: t...@muybien.org
> -
>
> Guarda que comer y no que hacer.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
On Fri, Feb 5, 2010 at 12:45 PM, Alan Gauld wrote:

>
> "Antonio de la Fuente"  wrote
>
>> the doctest for the slope function failed, because is expecting a
>>
>> floating point value and not an integer:
>>
>
> So convert it to a float.
>
> Or just
> return float(y2-y1/x2-x1)
>
> Alan why are you suggesting this, surely this will cause the decimal values
to be truncated?  Or does this somehow work differently in Python 3?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Comprehension question

2010-02-08 Thread Luke Paireepinart
On Mon, Feb 8, 2010 at 4:15 PM,  wrote:

> I've been trying to work my way through some 'beginner projects' I found
> around the web, one of them involves generating some random numbers.  I
> decided to use a list of lists, and I'm wondering if this is a valid
> comprehension...IDLE doesn't seem to mind, but maybe I lack the experience
> to know better:
>
> numbers = [[random.randint(1, 10) for x in range(5)] for y in range(5)]
>
> I'm using Python 3.1.  If this is valid, is there a shorter version or
> better way?
>

If Python executes it without throwing exceptions that means it's
syntactically valid.  Are you asking if it's semantically valid?  Well, that
depends what you're trying to do.  Are you trying to make a 5x5 matrix of
random numbers chosen from [1,2,3,4,5,6,7,8,9,10]?  In that case I'd say it
does what you want.  most people opt to use randrange rather than randint
though as it makes more sense when related to other range functions.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python

2010-02-08 Thread Luke Paireepinart
quite.

On Mon, Feb 8, 2010 at 8:54 PM, ailx ailx  wrote:

> python
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Just a Note

2010-02-12 Thread Luke Paireepinart
This doesn't make any sense.
What do you mean "tries to open up a news service"?  When you read the
e-mail?  What system are you using?

On Fri, Feb 12, 2010 at 8:30 PM, Randy Raymond wrote:

>  By the way, Alan Gauld's emails generate an error in my system.  His is
> the only emails I have a problem with so far.  At first it tried to open a
> News service.
>
> Randy Raymond
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-13 Thread Luke Paireepinart
On Sat, Feb 13, 2010 at 9:56 AM, patrice laporte wrote:

>
> Hi,
>
> Being in an exeption of my own, I want to print the name of the caller, and
> I'm looking for a way to have it.
>
> Could you tell us exactly why you want to do this?  It seems sort of
strange.  Also couldn't you pass the caller as an argument to your function?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-14 Thread Luke Paireepinart
I see why you would want the error messages but why is the default error
message not enough, that is why I am curious, and typically introspection on
objects is not necessary (for example, people often want to convert a string
into a variable name to store a value (say they have the string "foobar1"
and they want to store the value "f" in the variable "foobar1", how do they
change foobar1 to reference a string?  well you can just use exec but the
core issue is that there's really no reason to do it in the first place,
they can just use a dictionary and store dict['foobar1'] = 'f'  and it is
functionally equivalent (without the danger in the code)).  I get the
feeling that your issue is the same sort of thing, where an easier solution
exists but for whatever reason you don't see it.  I don't know if this is
true or not.  Here's my take on this:

>>> class x(object):
def __init__(self, fname):
self.temp = open(fname).read()


>>> a = x('foobar')

Traceback (most recent call last):
  File "", line 1, in# this is the
module it's in
a = x('foobar')#
this is the line where I tried to initialize it
  File "", line 3, in __init__  # which called
this function, which is the one that has the error
self.temp = open(fname).read()  #and the error
occurred while trying to perform this operation
IOError: [Errno 2] No such file or directory: 'foobar'  #and the error was
that the file 'foobar' could not be found.


This is implicitly stated that 'x' is the class with the method that had the
issue, and it was specifically the __init__ method, and the file that could
not be read was called 'foobar'.  How does this not satisfy your
requirements?  Is it the form of the output that you do not agree with (you
want it all on one line?)

I've never had issues with Python's exception statements, I've always had no
trouble finding where exceptions occurred, and I'm not sure what information
is missing from the traceback that you'd like to convey to the user.


On Sun, Feb 14, 2010 at 5:33 AM, patrice laporte wrote:

>
> 2010/2/13 Luke Paireepinart 
>
>
>>
>> On Sat, Feb 13, 2010 at 9:56 AM, patrice laporte wrote:
>>
>>>
>>> Hi,
>>>
>>> Being in an exeption of my own, I want to print the name of the caller,
>>> and I'm looking for a way to have it.
>>>
>>> Could you tell us exactly why you want to do this?  It seems sort of
>> strange.  Also couldn't you pass the caller as an argument to your function?
>>
>>
> Hi,
>
> I don't know if it's strange, maybe, so tell me why. Or maybe it's me
> Maybe the fact I'm à pure C coder for a longtime prevent me from thinking in
> Python, maybe my brain is only capable of thinking and viewing in C. and
> maybe there's an obvious way to solve my problem that I can't see yet... or
> maybe it's because I'm French, genetically programed to live in the past ?
> ... so this mailing list is my starting point to improve my Python
> understanding.
>
> And now, something different : what I want to do, and why.
>
> I got a class that takes a file name in its  __init__ method (it could be
> elsewhere, but why not here ?). Then, somewhere in that class, a method will
> do something with that file  name, such as "try to open that file".
>
> If the file do esn't exist, bing ! I got an exception "I/O Error n°2 : file
> doesn't exist".
>
> That's nice, I of course catch this exception, but it's not enough for the
> user : What file are we talking about ?  And how to tell the user  what is
> that file, and make him understand  he tell the app to use a file that
> doesn't exist ?
> And this is not enough for developer : where that error happened ? what
> class ? what method ?
>
> There is many solution, and mine is :
>
> - don't check for the existence of the file in __init__
> - don't use a default value for the file name parameter in __init__ : coder
> MUST provide it.
> - try/catch open(this_file_name) and if I got an IOErro exception, I
> re-raise my own exception with :
>- the name of the class where that IOError occured
>- the name of the method in that class that make that error occured
>- the name of the file the method tried to opened
>- some other info to help diagnostic
>
> Then my exception object can :
>- log in a file dedicated to the team (so, just me for the moment)
>- and/or log in a file dedicated to the user
>

Re: [Tutor] Editing html using python

2010-02-14 Thread Luke Paireepinart
On Sun, Feb 14, 2010 at 5:10 AM, Amit Sethi wrote:

> Hi I need to edit html programmatically . Sadly the html might be broken at
> places . I was using BeautifulSoup but there were lots of problems and it is
> also not maintained can some one guide me to any tutorials on editing html
> using lxml .
>

This is a rather specific question and if you really just want tutorials why
don't you just google for them?
Or are you also asking in a roundabout way if anyone on the list has a
better idea for parsing broken html?  It would help if you would take the
time to explain how the html is broken and what exactly "lost of problems"
with BeautifulSoup were.  Also I think beautifulsoup is part of the Python
standardlib now, isn't it?  Why do you think it is not maintained?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Sounding" Off, IDLE (Win7)

2010-02-18 Thread Luke Paireepinart
System Speaker is just the driver for the builtin speaker in your computer
(but it will redirect sound to your main speakers if you have some).  You'll
get sounds out of your regular speakers, you  just won't get system beeps
anymore, if you disable System Speaker.

On Thu, Feb 18, 2010 at 6:09 PM, Wayne Watson
wrote:

> Nothing to do with Ctrl-G. Cmd Prompt not open. So if you have a syntax
> error, no bell rings? I don't want to disable all sounds.
>
>
> On 2/17/2010 2:48 AM, Michael M Mason wrote:
>
>> Wayne Watson wrote on 16 February 2010 at 17:58:-
>>
>>
>>
>>> In Win7 IDLE, when I type in something with a syntax
>>> problem, a bell rings. How do I stop that? I've looked
>>> at Control Panel Sounds, but don't see anything of
>>> apparent use.
>>>
>>>
>> I don't get this on my Win7 machine. But anyway, the sound is
>> probably the same sound you get if you type CTRL-G at a command
>> prompt in a DOS box, in which case it isn't one of the sounds
>> you set in Control Panel.
>>
>> You can disable it using Device Manager. It's called 'System
>> Speaker' and it's under 'System devices'.  Right-click and
>> choose 'Disable'.
>>
>>
>>
>
> --
>"There is nothing so annoying as to have two people
> talking when you're busy interrupting." -- Mark Twain
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pyMVPA and OSError

2010-02-20 Thread Luke Paireepinart
On Thu, Feb 18, 2010 at 10:23 AM, Juli  wrote:

> Dear All,
>
> I am very much new to python, therefore I am likely to feel stupid
> about asking this. I need pyMPVA module to play around with some fMRI
> data. I have installed Python2.6 on Mac OS X Leopard. When I input >>>
> import mvpa i get a deprecation warning, which is not a problem,
> however when I try the following: >>> >>> import mvpa.suite as mvpa i
> do not get a deprecating warning however I get a number of errors that
> are as follows:
> >>> import mvpa.suite as mvpa
>


In addition to what Yaroslav mentioned, I may also suggest that it's
probably not a great idea to import a sub-package as the base package's
name.  You may have problems later if you want to import from mvpa. I.E. it
would be better to say
import mvpa.suite as suite
or
from mvpa import suite

Also I think you are supposed to use the syntax
from mvpa import suite as foobar
not
import mvpa.suite as foobar

but I'm not sure.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Superclass call problem

2010-02-20 Thread Luke Paireepinart
Your call to super is wrong. It should be super and you pass the class
and instance, then call init.

On 2/20/10, Alan Harris-Reid  wrote:
> Hi,
>
> I am having trouble understanding how superclass calls work.  Here's
> some code...
>
> class ParentClass():
> def __init__(self):
> do something here
>
> class ChildClass(ParentClass):
> def __init__(self):
>super().__init__(self) # call parentclass
> __init__ method
>do something else here
>
>
> When the super().__init__ line runs I get the error "__init__() takes
> exactly 1 positional argument (2 given)"
>
> Can anyone tell me where I have gone wrong?  I thought the self
> parameter should be passed to all class methods.
>
> TIA
> Alan Harris-Reid
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Luke Paireepinart
Can you explain what your function is doing and also post some test code to
profile it?

On Sat, Feb 20, 2010 at 10:22 AM, Andrew Fithian  wrote:

> Hi tutor,
>
> I'm have a statistical bootstrapping script that is bottlenecking on a
> python function sample_with_replacement(). I wrote this function myself
> because I couldn't find a similar function in python's random library. This
> is the fastest version of the function I could come up with (I used
> cProfile.run() to time every version I wrote) but it's not fast enough, can
> you help me speed it up even more?
>
> import random
> def sample_with_replacement(list):
> l = len(list) # the sample needs to be as long as list
> r = xrange(l)
> _random = random.random
> return [list[int(_random()*l)] for i in r] # using
> list[int(_random()*l)] is faster than random.choice(list)
>
> FWIW, my bootstrapping script is spending roughly half of the run time in
> sample_with_replacement() much more than any other function or method.
> Thanks in advance for any advice you can give me.
>
> -Drew
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fast sampling with replacement

2010-02-20 Thread Luke Paireepinart
On Sat, Feb 20, 2010 at 1:50 PM, Kent Johnson  wrote:

> On Sat, Feb 20, 2010 at 11:22 AM, Andrew Fithian 
> wrote:
> >  can
> > you help me speed it up even more?
> > import random
> > def sample_with_replacement(list):
> > l = len(list) # the sample needs to be as long as list
> > r = xrange(l)
> > _random = random.random
> > return [list[int(_random()*l)] for i in r]
>
> You don't have to assign to r, just call xrange() in the list comp.
> You can cache int() as you do with random.random()
> Did you try random.randint(0, l) instead of int(_random()*i) ?
> You shouldn't call your parameter 'list', it hides the builtin list
> and makes the code confusing.
>
> You might want to ask this on comp.lang.python, many more optimization
> gurus there.
>
> Also the function's rather short, it would help to just inline it (esp.
with Kent's modifications, it would basically boil down to a list
comprehension (unless you keep the local ref's to the functions), I hear the
function call overhead is rather high (depending on your usage - if your
lists are huge and you don't call the function that much it might not
matter.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Superclass call problem

2010-02-20 Thread Luke Paireepinart
>
>
> Hi Kent, thanks for the reply,
>
> Sorry, left out 'object' from my example.  The actual code already reads
> class ParentClass(object):
>
> Did you figure it out from my previous e-mail?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.path.basename() issue with path slashes

2010-02-20 Thread Luke Paireepinart
On Sat, Feb 20, 2010 at 6:11 PM, Dayo Adewunmi wrote:

> Shashwat Anand wrote:
>
>>
>> 
>>
>>
>>  for dirname, subdirname, filenames in os.walk(absolutePath):
>>  for filename in filenames:
>>  print ""
>>%(currentdir,filename,currentdir,filename)
>>
>>
>> I see a small typo here.
>> print ""
>> %(currentdir,filename,currentdir,filename)  should rather be print "> href=\"%s/%s\">"
>> %(currentdir,filename,currentdir,filename) ..
>> notice the slashes "%s/%s" in href tag and "%s\%s" in img tag.
>>
>> >>> filename = '1.jpg'
>> >>> absolutePath = os.getcwd()
>> >>> currentdir = os.path.basename(absolutePath)
>> >>> print ""
>> %(currentdir,filename,currentdir,filename)
>> 
>>
>>
>> ~l0nwlf
>>
> Arrrgh. Didn't see that forwardslash I put in there. It's fixed and works
> now.
> Thanks!
>
>
> If you're using OS functions you should NOT bank on the slashes being
forward-slashes.  This is platform-specific behavior.  You should use
os.path.split() to get the elements of your path and do a "/".join() on
them.  Otherwise your code will break on Windows because the path will be
denoted with backslashes.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What Editori?

2010-02-23 Thread Luke Paireepinart
On Tue, Feb 23, 2010 at 3:08 PM, Giorgio  wrote:

> O_O.
>
> I've downloaded some python examples from my debian server. Then, have
> edited one of them with pyscript. The IDLE (the real idle alan :D) was
> giving out a "unexpected indent" error, so i've checked again and again the
> code -it was ok-.
>
> Then, i've opened it in the IDLE. And there, ONLY there i see a double
> indentation for the line that was giving the error.
>
> I think it's because the script has been written on linux and i'm modifying
> it from windows, any idea or solution?
>
> Are you sure you're not mixing spaces and tabs?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python-based address standardization script?

2010-02-24 Thread Luke Paireepinart
On Wed, Feb 24, 2010 at 4:14 PM, Serdar Tumgoren wrote:

> Hey folks,
> Anyone know if there's a Python script floating out there to standardize
> U.S. addresses? I couldn't find anything on ActiveState or by Googling...I'm
> interested in something similar to this Perl module:
>
> http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm
>
> Just curious if anyone's seen an implementation in Python.
>
> I could really use this too, I haven't been able to find one.  Would you be
interested in porting the Perl one?  Maybe we could work on it if no one
knows of any Python versions?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python-based address standardization script?

2010-02-24 Thread Luke Paireepinart
On Wed, Feb 24, 2010 at 6:15 PM, Serdar Tumgoren wrote:

>
> Hey folks,
>>> Anyone know if there's a Python script floating out there to standardize
>>> U.S. addresses? I couldn't find anything on ActiveState or by Googling...I'm
>>> interested in something similar to this Perl module:
>>>
>>> http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm<http://search.cpan.org/%7Esderle/Geo-StreetAddress-US-0.99/US.pm>
>>>
>>> Just curious if anyone's seen an implementation in Python.
>>>
>>> I could really use this too, I haven't been able to find one.  Would you
>> be interested in porting the Perl one?  Maybe we could work on it if no one
>> knows of any Python versions?
>>
>
> Hey Luke,
>
> I'm definitely interested in porting it over and would be happy to
> collaborate on that project. I know a lot of folks that would *love* to get
> their hands on this type of code. Should I start a project on github? (I'm
> open to other VCS's that offer free web hosting for open source...)
>
> Anyone who wants to join in, just shout it out.
>
> Sure, just send me a link when it's up.  I don't have any experience with
git but I've wanted to learn so go ahead and use that.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wHY

2010-02-25 Thread Luke Paireepinart
YOU DON'T GET YOUR OWN MESSAGES BACK.

On Thu, Feb 25, 2010 at 5:11 PM, Kirk Bailey wrote:

> IS NOTHING FROM THE LIST COMING TO ME?
>
> --
>
>
> Cheers!
>  -Kirk D Bailey
>
>  THINK
> +-+
>  .*.| BOX |
>  ..*+-+
>  *** THINK
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyAutoRun

2010-02-26 Thread Luke Paireepinart
On Fri, Feb 26, 2010 at 1:41 AM, Zubin Mithra wrote:

> I have been using python for quite some time; however this is the
> first python project i have worked on.
>
> The code is hosted at http://github.com/zubin71/PyAutoRun
>
> The code needs re-factoring and feature additions; i have put up a
> TODO list there too. It`d be great if anyone could work on this; i
> intend to develop this further(with a bit of help) and will request
> for its addition into debian and ubuntu repositories, in time.
>
> Also, any kind of code-review, criticism, is also appreciated.
> However, it`d be awesome if you could just fork it at github, pull,
> modify and push. :)
>


I'm not too clear, perhaps you could explain what advantage this has over
just writing a shell script / makefiles?

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-12 Thread Luke Paireepinart
On Fri, Mar 12, 2010 at 4:03 AM, yd  wrote:

> Hi,
> I am new to programming, altough i have read a few books about OOP and
> O'Reily's Learning Python.
> I would like some critique on my first program, is it normal for it to be
> this long to do something simple?
> I know i could have turned some of these things into classes and functions
> but i don't know how to do that yet.
> Some critique of the algorithm and writing style or anything in general
> would help and any pointers would be appreciated.
> Thanks.
>
>
> One thing you should do is use more indentation.  Your program structure is
VERY hard to read with single space indentations.  Consider using 4-spaces.
This is not overtly long, I would say it's reasonable for a first program.
There are some things that you could probably group together, though.
Remember that code reuse is one of the core tenets of computer programming!

One example: area of square, parallelogram and rectangle are all the same.
You could do something like this (assuming user enters strings as choice
(rather than ints)):
if choice in ['rectangle', 'square', 'parallelogram']:
height = int(raw_input("Height: "))
if choice != 'square':
width = int(raw_input("Width: "))
else:
width = height
print "A %s with dimensions %sx%s has an area of %s." % (choice, height,
width, width*height)


Similarly with Ellipses and Circles, you can group some stuff together.

One thing, though.  Most people are still using Python 2.6 (which is what my
example above is in) and you appear to be using 3.0.  Perhaps you should
learn on 2.6 first, there are more resources and libraries available than
for 3.x at the moment.

I could probably make more comments but it's late and I need to go to bed,
hopefully that's a decent enough start.

Also (just FYI - you didn't do anything wrong) when replying to a post
please use "reply-all" so that the group will get the message.  If you use
"reply" it will just come straight back to me.
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-12 Thread Luke Paireepinart
Ray, please reply on-list in the future in case someone else has input.

On Fri, Mar 12, 2010 at 8:01 PM, Ray Parrish  wrote:

> Luke Paireepinart wrote:
>
>print "A %s with dimensions %sx%s has an area of %s." % (choice, height,
>> width, width*height)
>>
>>
> Isn't it a little more understandable to use a construct like the
> following?
>
> >>> print "The area of a " + Choice + "is " str(Width) + " x " +
> str(Height) + " equals " + str(Width * Height) + " square feet"
>
> The area of a rectangle is 12 x 10 equals 120 square feet.
>
> I find that putting the variables on the end like that, when you're not
> actually applying any special formatting to them makes it less readable when
> I'm debugging my stuff, or when someone else is reading my code, and trying
> to understand it.
>
>
> Your version creates at least 10 intermediate strings before outputting.
Remember strings are immutable in Python.
So you're constructing strings
The area of a
The area of a rectangle
The area of a rectangle is
12
The area of a rectangle is 12
The area of a rectangle is 12 x
10
The area of a rectangle is 12 x 10
The area of a rectangle is 12 x 10 equals
120
The area of a rectangle is 12 x 10 equals 120
The area of a rectangle is 12 x 10 equals 120 square feet

With string formatting you avoid all of these intermediate strings, so it's
arguably more efficient.
Other than just viewing from a performance standpoint though, I find it much
easier to read my version, because any computation required takes place at
the end of the line.
For example, your inline str(width*height) requires you to read the whole
line to see it.

It's really a personal thing, it's easier for me to read the formatting
version than the string concatenation version, in most cases.
Now if you had used the comma convention I would have seen your point.  This
is, I think, the easiest to read of all 3
area = width * height
print "The area of a", choice, "is", width, "x", height, ", which equals",
area, "square feet."

Also, why are you capitalizing variable names?  That's a pretty unusual
convention.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-12 Thread Luke Paireepinart
On Fri, Mar 12, 2010 at 8:30 PM, Andre Engels  wrote:

> On Sat, Mar 13, 2010 at 3:11 AM, Ray Parrish  wrote:
> > Andre Engels wrote:
> >>
> >> On 3/12/10, yd  wrote:
> >>>  else:
> >>>raise Exception('{0}, is not a valid choice'.format(choice))
> >>>
> >>
> >> This will cause the program to stop-with-error if something wrong is
> >> entered. I think that's quite rude. I would change this to:
> >>  else:
> >>print('{0}, is not a valid choice'.format(choice))
> >>
> >
> > Here's what I get from that, could you please explain why?
>
> You're probably using Python 2.4 or 2.5; the .format method has been
> introduced in Python 2.6, and is considered the 'standard' way of
> working in Python 3. For older Python versions, this should read
>
> print('%s, is not a valid choice'%(choice))
>
> Also you don't have to use parenthesis around single items, and also print
is not usually used as a function either.
So really for older versions the convention would be
print "%s, is not a valid choice" % choice

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-13 Thread Luke Paireepinart
On Sat, Mar 13, 2010 at 3:03 AM, Alan Gauld wrote:

> "Ray Parrish"  wrote
>
>>print "A %s with dimensions %sx%s has an area of %s." % (choice,
>>> height, width, width*height)
>>>
>>>  Isn't it a little more understandable to use a construct like the
>> following?
>>
>>  print "The area of a " + Choice + "is " str(Width) + " x " +
>>>>>
>>>> str(Height) + " equals " + str(Width * Height) + " square feet"
>>
>
> It depends on where you come from.
> Those of us brought up on C or COBOL are used to separating the
> presentation from the data. Those brought up with PASCAL and BASIC are used
> to iterleaving data with presentation.
>
> One thing - you don't need all the str() calls in your example, print
> already calls str() for you. Also comma separators are better than + signs
> since the plus operation on strings is quite expensive - you create a new
> string for each addition.
>
>
> print actually doesn't call str if you use concatenation.  So the str()
calls are necessary if you do not use "," but use "+" instead.
So there are at least 2 reasons why + is worse than comma.
Another thing to be aware of is that if you use commas,
print inserts a space in the string, which may be either an advantage or a
disadvantage depending on what you're trying to do.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program

2010-03-13 Thread Luke Paireepinart
On Sat, Mar 13, 2010 at 12:04 PM, Ray Parrish  wrote:

> Luke Paireepinart wrote:
>
>>
>> Your version creates at least 10 intermediate strings before outputting.
>> Remember strings are immutable in Python. So you're constructing strings
>> The area of a
>> The area of a rectangle
>> The area of a rectangle is
>> 12
>> The area of a rectangle is 12
>> The area of a rectangle is 12 x
>> 10
>> The area of a rectangle is 12 x 10
>> The area of a rectangle is 12 x 10 equals
>> 120
>> The area of a rectangle is 12 x 10 equals 120
>> The area of a rectangle is 12 x 10 equals 120 square feet
>>
>> With string formatting you avoid all of these intermediate strings, so
>> it's arguably more efficient.
>> Other than just viewing from a performance standpoint though, I find it
>> much easier to read my version, because any computation required takes place
>> at the end of the line.
>> For example, your inline str(width*height) requires you to read the whole
>> line to see it.
>>
>> It's really a personal thing, it's easier for me to read the formatting
>> version than the string concatenation version, in most cases.
>> Now if you had used the comma convention I would have seen your point.
>>  This is, I think, the easiest to read of all 3
>> area = width * height
>> print "The area of a", choice, "is", width, "x", height, ", which equals",
>> area, "square feet."
>>
>> Also, why are you capitalizing variable names?  That's a pretty unusual
>> convention.
>>
>

>  Thanks for letting me know how inefficient my method is. I'll remember
> that, and apply your suggestions to my code from now on. So, you're saying
> that the commas method also does not suffer from the overhead of creating a
> bunch of individual strings?
>


Yes, the 'comma method' is actually doing something sorta tricky behind the
scenes: it's creating a tuple and passing it to print.
Look what happens when you just comma-separate stuff normally:
>>> 'hello','how','are','you?'
('hello', 'how', 'are', 'you?')

This implicit tuple conversion is useful in other situations too:
>>> a, b = 1 , 2
>>> a
1
>>> b
2

this is creating the tuple (1,2) and then iterating over the tuple and
assigning values to whatever's on the left hand side (a, b in this case).
And you can abuse it if you really want to, to force things into tuples:
>>> a,
(1,)


So what's happening when you call print with the tuple, is that print is
basically doing this behind the scenes:
for item in tuple:
sys.stdout.write(item)
sys.stdout.write(" ")
sys.stdout.write("\n")

Of course it doesn't do this in Python but rather in C, at a lower level,
but that is basically the idea.
If print gets a list or a tuple of strings it will iterate over them and
output them to standard out with spaces.  This doesn't incur the string
concatenation overhead.


Truthfully, the penalty for concatenating strings is not that big, the
reason most people don't use the + method is just because they find it
harder to read/follow.
Or, I should say: the penalty for concatenating strings _that you're going
to output_ is not that big, because you tend to output short strings and not
a lot of them,
otherwise the output is pretty much unreadable.

If you do something like this:
x = ""
for i in range(100):
x += str(i) + " "

You'd probably want to change it to
y = []
for i in range(100):
y.append(i)
x = " ".join(map(y, str))

 -Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] movement controls

2010-03-18 Thread Luke Paireepinart
You should probably decouple the view from the model - have the character
move around in a 2d plane in the model and then just draw the level in a
certain area around the 2d coordinates of the character.

On Thu, Mar 18, 2010 at 6:51 PM,  wrote:

>  A little stuck and could do with any sudjestions.
>
> Aim:-
> When the character goes past the middle of the screen, the background &
> level move downwards so the character can get to higher places, think sonic
> the hedgehog.
>
> This is the bit I'm having problems with, I can get the character to get to
> the center, the background moves up & down but the character won't go back
> down when the level returns to normal height.
>
> if bkGroundRect['rect'].top < 0 and charRect['rect'].top <
> winCenterRect.top:
>
> bkGroundRect['rect'].top += spY
> platRect['rect'].top += spY
> jumpRect.top += spY
> charRect['dir'] = STOP
>
>
> if levelRect['rect'].bottom > winHeight and charRect['rect'].centery ==
> winCenterx:
> bkGroundRect['rect'].bottom -= spY
> platRect['rect'].bottom -= spY
> #jumpRect.bottom -= spY
> charRect['dir'] = STOP
>
>   #--this won't execute ? --#
> if levelRect['rect'].bottom <= winHeight:
> if charRect['rect'].centery >= winCenterx and
> charRect['rect'].centerx < jumpRect.centerx:
> charRect['dir'] = DOWN
>
> I've included the whole code as a note pad so the above makes more sense,
> don't worry about all the comments, that's just for my convenience.
>
> Thanks guys
>
> Mark
>
> 'knight meets wall, wall won't let knight pass, knight says 'neh'
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Movement controls useing pygame

2010-03-19 Thread Luke Paireepinart
Are you just reposting this exact same e-mail to the list because you didn't
see my reply to the other one, or are you ignoring what I said and posting
the same message again, hoping someone else will answer?
I hope it's not the latter, that's kind of insulting.  The least you could
do is say that my idea didn't make sense or wouldn't work for you in this
case.

-Luke

On Thu, Mar 18, 2010 at 7:45 PM,  wrote:

>  A little stuck and could do with any sudjestions.
>
> Aim:-
> When the character goes past the middle of the screen, the background &
> level move downwards so the character can get to higher places, think sonic
> the hedgehog.
>
> This is the bit I'm having problems with, I can get the character to get to
> the center, the background moves up & down but the character won't go back
> down when the level returns to normal height.
>
> if bkGroundRect['rect'].top < 0 and charRect['rect'].top <
> winCenterRect.top:
>
> bkGroundRect['rect'].top += spY
> platRect['rect'].top += spY
> jumpRect.top += spY
> charRect['dir'] = STOP
>
>
> if levelRect['rect'].bottom > winHeight and charRect['rect'].centery ==
> winCenterx:
> bkGroundRect['rect'].bottom -= spY
> platRect['rect'].bottom -= spY
> #jumpRect.bottom -= spY
> charRect['dir'] = STOP
>
>   #--this won't execute ? --#
> if levelRect['rect'].bottom <= winHeight:
> if charRect['rect'].centery >= winCenterx and
> charRect['rect'].centerx < jumpRect.centerx:
> charRect['dir'] = DOWN
>
> I've included the whole code as a note pad so the above makes more sense,
> don't worry about all the comments, that's just for my convenience.
>
> Thanks guys
>
> Mark
>
> 'knight meets wall, wall won't let knight pass, knight says 'neh'
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] movement controls

2010-03-19 Thread Luke Paireepinart
On Fri, Mar 19, 2010 at 4:09 AM,  wrote:

>  But yes, I'm not quite sure about what you mean. I guess you mean keep
> the character on the x plane <> then for the jumping movements move the
> level? what do you mean by 'You should probably decouple the view from the
> model'
>
>
> and it's preferable not to use html when sending e-mails, 'cause your font
settings don't necessarily look good on other people's computers.

You should really be asking this on the Pygame list, and you probably still
should.

Having said that... I'll try to answer your question.

The way you're currently doing it, you have all of your sprites' coordinates
just stored in random variables, and you're calculating where they should be
on the screen and then drawing them directly, right?
In other words, if player.x = 100 and player.y = 200 then he is located at
100, 200 on the screen?

Having a view and a model relates to the MVC (model-view-controller)
paradigm in programming.

Basically think of it like this.

Suppose I have a window that I'm looking out, and my dog is outside running
around somewhere.  Now you walk by the window.  Does it make more sense for
me to model your interaction with my dog in relation to what I can see out
of my window, or should I model your interaction with the dog in a separate
space, independent of where I may be looking?

Say I want to describe your position to my friend who lives up and to the
right of me.  Would I say "see that guy by the bench petting my dog?" or
would I say "see the guy that is 12 meters forward and 1 meter to the right
of the center of my window?"  The friend doesn't have any idea what
perspective _I_ view the world from, and he really shouldn't have to.

SO in the MVC framework, you model your _world_ space and your VIEW is just
an outside observer "peeking" at the current state of the world.  So, for
example, say your world is a grid
of 1000 x 8000 units, and your character is located at 200x200.  There might
be an enemy moving around at 800x2000, who may not be on the screen, but I
still want to model that enemy moving around,
so that when the character gets over there, the enemy will be in a new
location.  Or maybe he'll walk over and be on the screen.

When you do it this way, you can merely say "render everything that is
around my player's current position" and then all your problems are solved.
The view will automatically follow the player, and when he jumps up, the
view will raise with him.  If you set an upper and lower limit, then the
view will naturally not move until the player moves past a certain point of
the screen.

If you continue to refer to the game objects in terms of their graphical
position in relation to the screen, it's going to get very convoluted.

In order to  "decouple your view from your model" you will likely have to
rewrite a lot of your code -- the key here is that you should've written it
this way (MVC) in the first place.

Read up more on MVC, and specifically how it relates to game design.

Also, when you reply,
use Reply to All
otherwise your reply is only seen by me, not by the other members on the
list.

Good luck,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Efficiency and speed

2010-03-19 Thread Luke Paireepinart
On Fri, Mar 19, 2010 at 3:17 PM, James Reynolds  wrote:

> Here's another idea I had. I thought this would be slower than then the
> previous algorithm because it has another for loop and another while loop. I
> read that the overhead of such loops is high, so I have been trying to avoid
> using them where possible.
>
> def mcrange_gen(self, sample):
> nx2 = self.nx1
> for q in sample:
> for a in nx2:
> while a > q:
>  pass
> yield a
> break
>
> One thing to consider is whether you need to run this simulation online or
offline.
That is, whether you can reorder your sample space.

IFF you can reorder your sample space, then this algorithm can be extremely
simplified / sped up,
because then you can sort both the sample space and the binning list in
numerical order
Then you simply do a single pass through each list and only spend O(n+m)
time to categorize your entire sample space.
Sort of how a "merge" step of "merge sort" works, except rather than
emitting the sort order you would just be emitting
tuples with the sample value and its corresponding bin index.

If this doesn't make sense let me know.
If you are able to run the sim offline and reorder your sample space,
and I'm not just being dumb & misunderstanding what you're trying to do
(which is entirely possible),
try it this way.  If you have problems with my explanation, let me know and
I'll try to explain it better.

HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding duplicates entry in file

2010-03-20 Thread Luke Paireepinart
On Sat, Mar 20, 2010 at 11:34 AM, Ken G.  wrote:

> What is a method I can use to find duplicated entry within a sorted numeric
> file?
> I was trying to read a file reading two lines at once but apparently, I can
> only read one line at a time.  Can the same file be opened and read two
> times within a program?
>
> For example, a file has:
>
> 1
> 2
> 2
> 3
> 4
> 4
> 5
> 6
> 6
>
> The newly revised file should be:
>
> 1
> 2
> 3
> 4
> 5
> 6
>
> Again, thanking the group for their input,
>
>
One-liner:
open("output.txt", "w").write("\n".join(sorted(set([i.strip() for i in
open("input.txt")]


Just for fun :)

also, in your algorithm, why are you assuming there are at most 1 extra
entries in the case of a duplicate?  Why not generalize it for all
duplicates?
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding duplicates entry in file

2010-03-20 Thread Luke Paireepinart
On Sat, Mar 20, 2010 at 4:50 PM, Ken G.  wrote:

>  Thanks for the info.  I already adopted a program from another person and
> it works like a charm.   As for your question, I had no idea of if I had
> duplicate or more as there was some 570 line items.  I whittled it down to
> 370 line entries.  Whew.
>

Can you please try to post to the list in plain-text rather than HTML?  it
is very hard to read your font on my system.

Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding duplicates entry in file

2010-03-20 Thread Luke Paireepinart
On Sat, Mar 20, 2010 at 10:20 PM, Steven D'Aprano wrote:

> On Sun, 21 Mar 2010 09:10:52 am Luke Paireepinart wrote:
> > On Sat, Mar 20, 2010 at 4:50 PM, Ken G. 
> wrote:
> > >  Thanks for the info.  I already adopted a program from another
> > > person and it works like a charm.   As for your question, I had no
> > > idea of if I had duplicate or more as there was some 570 line
> > > items.  I whittled it down to 370 line entries.  Whew.
> >
> > Can you please try to post to the list in plain-text rather than
> > HTML?  it is very hard to read your font on my system.
>
>
> What client are you using? Ken's post includes both a plain text part
> and a HTML part. Any decent mail client I know of gives you the choice
> of which to view.
>
>
gmail auto-selects html, apparently.
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Prime numbers

2010-03-28 Thread Luke Paireepinart
On Sat, Mar 27, 2010 at 5:08 PM, yd  wrote:

>
> Having a problem finding the first 1000 prime numbers, here is my code:-
>
> print(2)
> n =3
> counter =1
> while counter <=1000:
>   for x in range(3,int((n**0.5)),2):
> if n%x != 0:
>   print(n)
>   n+=1
>   counter+=1
> else:
>   n+=1
>
> The problem is, it prints 2 and then does nothing, yet if i try and close,
> it says program is still running do you want to kill it, is there a way to
> do this with lists, i know python has a prime function but i am not going to
> use it because i want to solve this problem without 'cheating'.Thanks.
>
>
> What 'problem' are you trying to solve?
In general, anytime you can use a premade solution, you are at an advantage,
not cheating.
That's one of the marks of a truly good programmer - being able to reuse as
much code as possible.
Unless it's a homework problem and he said "don't use the prime function"
because in this case, your goal is to learn how to write a prime function,
not to calculate primes.
I.E. it's the doing, not the task.  And if that's the case, please let us
know that it's homework.  We will still help you, we just follow certain
guidelines
when providing homework assistance so as not to "give it away" and still
allow you to reason / come up with the solution on your own, as your teacher
probably intended.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] the binary math "wall"

2010-04-20 Thread Luke Paireepinart
On Tue, Apr 20, 2010 at 11:58 AM, Lowell Tackett
 wrote:
> I'm running headlong into the dilemma of binary math representation, with 
> game-ending consequences, e.g.:
>
>>>> 0.15
> 0.14999
>
> Obviously, any attempts to manipulate this value, under the misguided 
> assumption that it is truly "0.15" are ill-advised, with inevitable bad 
> results.
>

Yes, floats are slightly inaccurate.
No, this usually doesn't cause problems.

You can use the decimal module if you want.
But I think your problem is that your math is wrong.
You are assuming that your float values are precise and they are not.
You must check ranges when dealing with float values, not for specific values.
I.E. you should never depend on a value being 1 in a float calculation,
instead your equations need to be robust enough to deal with values
very close to 1 as well.
If your equations cannot handle this, then coerce the value to 1.
if .999 < i < 1.1:
i = 1

And before you say "but that is just a hack", no, that is the nature
of floating-point values.  No one ever claimed that they were precise
or that you should depend on their values being precise.

If you really care so much, use the decimal module.
But you really just need to adapt your formulas from the ideal to the
reality, in which the values are not necessarily complete.

May I suggest another approach though?
Why even process these values as floats?

Consider this:
>>> a = 18.15
>>> a
18.149
>>> a = '18.15'
>>> degree, min = map(int, a.split('.'))
>>> degree
18
>>> min
15

Supposing you get your input as a string.
Basically the second you let your value end up stored as a float,
there's no turning back.  You need to get ahold of this value before
it becomes a float and deal with it in a different way.  The most
straightforward is to deal with the parts individually as integers.

Eventually you will develop a distrust for floats and you will
intrinsically know where and when you should / shouldn't use them ;)

Hope that helps,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Changing Default Install Path on Windows

2010-04-21 Thread Luke Paireepinart
Hi guys,
my first post to the list with a question rather than a response in a
few years, I think :)

(NOTE: I solved my question while writing this e-mail, I'm just
mailing this to the list for future users now)

I'm running Windows 7 64-bit.

I currently have 3 python installs.
First I installed the 64-bit version of Python 2.6 to C:\Python26,
then realized that it doesn't have as much lib support.
Then I installed the 32-bit version to C:\Python26x86
Everything worked fine after this (installs, etc. all went to the
proper site-packages.)

Then I installed Panda3D and normally it doesn't hijack your Python
install but I guess in this case I accidentally told it to become
default.

Now, when I try to run an installer, it finds the Panda3D Python first.

I'm getting really frustrated because I can't figure out why it's
finding the Panda3D Python.
I don't understand how the multiple version precedence works.


In my registry, HKLM / SOFTWARE / Python, all I have is PythonCore/2.6
and all references in here (PythonPath, InstallPath, etc. etc.) all
reference the FIRST python install (C:\Python26)

My PATH environment variable is:
C:\Users\rabidpoobear>echo %path%

C:\Program Files (x86)\PC Connectivity
Solution\;C:\Python26x86\Lib\site-packages\PyQt4\bin;C:\Program Files
(x86)\NVIDIA Corporation\PhysX\
Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files\TortoiseSVN\bin;
C:\python26x86;C:\Program Files
(x86)\Graphviz2.26.3\bin;C:\jython2.5.1;C:\Panda3D-1.7.0\bin

the Panda3D bin directory does NOT contain a python.exe, it only
contains panda3d stuff.  The Panda3d python install is in
C:\Panda3D-1.7.0\python

I cannot find any references to the Panda3D python install ANYWHERE.

Yet anytime I try to run an installer, it tries to install there.  And
the stupid "helpful" python installers that auto-find the directory do
not let you change it.
They make the (faulty) assumption that they're correct.

-

I figured out the solution, I just did a Find on my entire registry
and found C:\Panda3D-1.7.0 in
HKLM\Software\Wow6432Node\Python\PythonCore\2.6\InstallPath .
After some investigation it seems that the special Wow6432Node has to
do with 64-bit versions of Windows running 32-bit versions of Python.

So the lesson we've learned today is that your 64-bit Python install
path should will be where it normally is
(HKLM\Software\Python\PythonCore\version\InstallPath)
but your 32-bit path will be in that special WowNode directory.

Hope that helps someone in the future,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-04-27 Thread Luke Paireepinart
On Tue, Apr 27, 2010 at 10:12 PM, Marco Rompré  wrote:
> Oups my posting was too big!!!
>
> On Tue, Apr 27, 2010 at 11:04 PM, Marco Rompré 
> wrote:
>>
>> Why is none of my items button works In this, I have two files and in
>> my second file I imported all the function of the first one
>>
>> Here is my codes and my error code  for the two files please help me:
>> Traceback (most recent call last):
>>
>>
>>   File "F:\School\University\Session 4\Programmation
>> SIO\magasingolfvues.py", line 426, in 
>>     app = App(racine, "magasinmodele.txt")
>>   File "F:\School\University\Session 4\Programmation
>> SIO\magasingolfvues.py", line 23, in __init__
>>     ItemsFrame(contexte, item)
>> NameError: global name 'item' is not defined
>> >>>
>>
>>[snip lots of code]


You're not going to get a very good reply with a post like this.
First of all, it's homework, so we aren't going to give you answers
(not that we would anyway).
Secondly, if you have a problem, you need to clearly specify what the
problem is, and clearly outline what you did to try to solve it, and
why you think that didn't work, and some general indication that you
are trying things.
We're not here to just give people answers, we're here to help you
when you get stuck learning on your own.
It's much more rewarding in the end, trust me.

Also why do you think the problem you're having is your "items button
[doesn't] work" when it's pretty clear from the traceback that your
code crashes due to trying to access a variable that doesn't exist?

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Regex to produce text

2010-04-27 Thread Luke Paireepinart
On Wed, Apr 28, 2010 at 1:27 AM,   wrote:
> Dear All,
>
> Quick question:
>
> Is there an way of using the regex patterns to produce text, instead of 
> matching it?
>
> E.g.:
> pat = re.compile("ab?d")
> pat.getListofPossibleText()
>

There's no end to the length of many patterns so this would be fairly pointless.
For example, what would getListofPossibleText do for the pattern ".*" ?

I think the better question is: what are you trying to do?
Or perhaps: Why do you think you need to solve your problem this way?

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python beginner having troubles understanding word lists and character lists

2010-04-28 Thread Luke Paireepinart
On Wed, Apr 28, 2010 at 2:06 PM, Daniel  wrote:
> Hello, I'm a beginner programmer, trying to learn python. I'm currently
> reading The programming
> Historian,http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> I stumbled into lists of words and lists of characters. I have no
> explications in that book for those two and I didn't found some explications
> on the web. Could you point me to a link or something where I can read about
> them? I don't seem to understand why they are used.
> thank you so much!
>

Daniel,
I'm not too clear on what you're talking about.
What part is confusing you exactly?
Could you provide a code example?
Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python list, right! but concretely?

2010-05-01 Thread Luke Paireepinart
2010/5/2 spir ☣ :
> Hello,
>
> Is there anywhere some introduction material to the implementation of python 
> lists (or to fully dynamic and flexible sequences, in general)?
> More precisely, I'd like to know what kind of base data-structure is used 
> (linked list, dynamic array, something else -- and in case of array, how is 
> resizing computed). Also, how is "generics" (element are of free type, and 
> even heterogeneous) managed?

There's no distinction between the types, a list is just a list of
Objects, and they can be anything, they can be lists themselves, or a
primitive data type like an int (which is still an Object in Python),
or whatever.  Remember everything in Python inherits from the generic
class 'object' or it inherits from a class that inherits from
'object'.

I have no idea what the implementation actually is, but I have read
about it somewhere so I do know that it's possible to find the
implementation details.

Good luck,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
> If that looks a bit clumsy, use a generator expression:
>
> linesToDelete = [x for x in lines if x.startswith('%')]
> for x in linesToDelete:
>   lines.remove(x)
>
> which idiomatically should probably become:
>
> for x in [y for y in lines if y.startswith('%')]:
>   lines.remove(x)
>
>

Hmm, why not
lines = [line for line in lines if not line.strip().startswith('%')]

note that for a significantly large file this might be sorta slow
(since it's an extra iteration over the list), whereas the 'breaking
out of the loop on comment lines' approach may be a little faster.
it's probably not significant for this application though.

Also, yeah, try really hard not to modify lists you're iterating over.
 In almost every case, it's not actually what you need to do.  It's
akin to people wanting to create variable names from strings, before
they discover that dictionaries are the correct response.

Hope that helps,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel  wrote:
>
> You are modifying the list during iteration, so the size changes and the
> iterator gets diverted. Don't remove the line, just skip over it, e.g.
>
>    def read_package_names(open_text_file):
>        """Read lines, strip any comments and return only the
>        package names found.
>        """
>        for line in open_text_file:
>            if '%' in line:
>                # take only the part before the '%'
>                line = line.split('%', 1)[0]
>            line = line.strip()
>            if line:
>                yield line

And here if you wanted all the text on the line before the first '%'
as a list comprehension it would be something like this:

lines = [line[:line.index('%')] for line in lines if not
line.strip().startswith('%')]



>
>    with open('packages.txt') as f:
>        for package_name in read_package_names(f):
>            print package_name
>

What's this bizarre syntax?
I thought they changed for loop interations so that if you did
for line in open('packages.txt'):
 etc...

it would automatically close the file handle after the loop terminated.
Have I been wrong this whole time?

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel  wrote:
> Luke Paireepinart, 03.05.2010 10:27:
>> What's this bizarre syntax?
>
> Look it up in the docs, it's called "with statement". Its purpose here is to
> make sure the file is closed after the execution of the statement's body,
> regardless of any errors that may occur while running the loop.
>
>
>> I thought they changed for loop interations so that if you did
>> for line in open('packages.txt'):
>>      etc...
>>
>> it would automatically close the file handle after the loop terminated.
>> Have I been wrong this whole time?
>
> Yes. The fact that the file is automatically closed after the loop is an
> implementation detail of CPython that does not apply in other Python
> implementations.
>

So why is it an implementation detail?  Why is it not universally like that?
You never have an explicit reference to the file handle.  When it gets
garbage-collected after the loop it should get rid of the file handle.

I mean, where is the line between 'implementation details' and
'language features'?  What reason is there to make lists mutable but
strings immutable?  Why aren't strings mutable, or lists immutable?

It all seems pretty arbitrary to me.

Also, the with syntax is kind of ugly.  So is the 'for/else' syntax.
They are not as intuitively clear as most of the other language
constructs to me.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
2010/5/3 spir ☣ :
> On Mon, 03 May 2010 10:55:11 +0200
> Stefan Behnel  wrote:
>
>> Luke Paireepinart, 03.05.2010 10:27:
>> > On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
>> >>                 line = line.split('%', 1)[0]
>> >
>> > lines = [line[:line.index('%')] for line in ...
>>
>> Agreed that
>>
>>      line = line[:line.index('%')]
>>
>> is slightly more readable than
>>
>>      line = line.split('%', 1)[0]
>
> But, to my eyes,
>    endpos = line.index('%')
>    line = line[:endpos]
> is even more readable ;-)
>

I prefer this:
search_string_percent_sign = '%'
end_position_in_line = line.index(search_string_percent_sign)
temp = line[:end_position_in_line]
line = temp

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help required to count no of lines that are until 1000 characters

2010-05-11 Thread Luke Paireepinart
On Tue, May 11, 2010 at 1:00 PM, ramya natarajan  wrote:
> Hello, I have to read lines from
> files exactly upto 1000 characters.
>But the problem is its reading entire line and not stopping
> excatly in 1000 characters. Can some one help what mistake i am doing here?.
>
>    log = open('/tmp/new.txt','r')
>    lines,char = 0,0
>    for line in log.readlines():
>     while char < 1000 :
>     for ch in line :
>  char += len(ch)
>     lines += 1
>   print char , lines

here's the pseudocode of what you're doing, it might help you
understand what the problem is:
for every line in the file:
if the character count is less than 1000, add the length of the
current line.

You are missing a condition.

Here is another version of your code that has the same problem, see if
this helps make it clearer:
lines, chars = 0,0
with open('/temp/new.txt') as f:
for line in f:
if chars > 1000: break
chars += len(line)


This sounds a lot like a homework problem so I won't give you the
answer, but I hope that helps.


Also do you realize you are counting newlines as well?  You may not
want to do this, depending on your intended application.

Hope that helps,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Luke Paireepinart
I'd have rather you top-posted, then I wouldn't have wasted 30 seconds
scrolling past a bunch of irrelevant crap that I just gloss over
anyway.
If I want context I'll read the previous messages in the thread.
but that's just MHO.
-Luke

On Tue, May 11, 2010 at 9:28 PM, Dave Angel  wrote:
> (1. Please don't top-post.  It gets everything out of sequence, and is the
> wrong convention for this forum
> 2. Be sure and do a reply-all, so that the message goes to the forum.  I'm
> not here to give private advice.
> 3. Use your editor's reply-quoting so that we can tell who wrote which
> parts.  Normally, you'll see that as either a leading ">" character or as a
> "!" character.  And one can tell which parts were written by whom by
> counting the number of those at the beginning of each line)
>
> For my real response, see the end of the message, where it belongs.
>
> Sivapathasuntha Aruliah wrote:
>>
>> Dave
>> Thank you very much for your response. I think I have problem with both
>> Python23 & Python31. Please help.
>>
>> Python23 : The program works but programs written by Mark Summerfield in
>> his book Programming in Python3 does not work.
>> Python 31: When I run this program it says in the pop up window "
>> C:\py3eg\csv2html1_ans.py is not a valid Win32 application" and on the the
>> dos box it says Access is denied.
>> Below is the dos box contents
>>
>>
>> C:\>cd python31
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\quadratic.py
>> Access is denied.
>>
>> C:\Python31>python C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>python.exe C:\py3eg\hello.py
>> Access is denied.
>>
>> C:\Python31>cd..
>>
>> C:\>cd python23
>>
>> C:\Python23>python.exe C:\py3eg\hello.py
>> ('Hello', 'World!')
>>
>> C:\Python23>python.exe C:\py3eg\print_unicode.py
>> Traceback (most recent call last):
>>  File "C:\py3eg\print_unicode.py", line 30, in ?
>>    print_unicode_table(word)
>> NameError: name 'print_unicode_table' is not defined
>>
>> C:\Python23>python.exe C:\py3eg\quadratic.py
>>  File "C:\py3eg\quadratic.py", line 14
>>    except ValueError as err:
>>                       ^
>> SyntaxError: invalid syntax
>>
>>
>>
>>
>> Regards,
>> Siva
>> Test Equipment Engineering
>> Amkor Technology (S) Pte Ltd
>> 1 Kaki Bukit View
>> #03-28 TechView Building
>> Singapore 415941
>> Tel: (65) 6347 1131
>> Fax: (65) 6746 4815
>>
>>
>>
>> Dave Angel 
>>
>>
>> 05/12/2010 09:50 AM
>>
>>
>> To
>> Sivapathasuntha Aruliah/S1/a...@amkor
>> cc
>> tutor@python.org
>> Subject
>> Re: [Tutor] (no subject)
>>
>>
>>
>>
>>
>>
>>
>>
>> Sivapathasuntha Aruliah wrote:
>>
>>>
>>> Hi
>>> I am learning Python. When I tried to run any of the program for example
>>>
>>
>>
>>>
>>> csv2html1_ans.py it displays the following message. This error is coming
>>>
>>
>>
>>>
>>> on both Python24 & Python 31. That is whether i give the any one of the
>>> following command
>>>
>>> COMMAND GIVEN
>>> 1.C:\python24\python.exe C:\py3eg\quadratic.py
>>> 2.C:\python31\python.exe C:\py3eg\quadratic.py
>>>
>>> A message below appears with the program name. Please advice me how to
>>>
>>
>> get
>>>
>>> over from this issue
>>> ERROR MESSAGE
>>> command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application
>>>
>>> Regards,
>>> Siva
>>> Test Equipment Engineering
>>> Amkor Technology (S) Pte Ltd
>>> 1 Kaki Bukit View
>>> #03-28 TechView Building
>>> Singapore 415941
>>> Tel: (65) 6347 1131
>>> Fax: (65) 6746 4815
>>>
>>>
>>
>> Please copy and paste the actual contents of your DOS box, rather than
>> paraphrasing.  COMMAND hasn't been the normal shell name since Win95 days.
>>  You can't use numbers in front of commands in any shell I've used.  The
>> error message refers to a different file than anything you specified in your
>> commands.
>>
>> What OS are you using?
>>
>> DaveA
>>
>>
>>
>>
&g

Re: [Tutor] (no subject)

2010-05-11 Thread Luke Paireepinart
I'm just not going to quote previous threads because with my top-posting and
dave's bottom-posting and whatever the heck Siva's posting was... whatever.
 Read previous e-mails if you need context.

Siva is it possible that you accidentally installed the 64-bit version of
python 3.1?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-12 Thread Luke Paireepinart
>
> Siva is it possible that you accidentally installed the 64-bit version of 
> python 3.1?
> Hi Luke
> I checked again and found that Python Shell has the following which is win32
>
> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] 
> on win32
> Type "copyright", "credits" or "license()" for more information.
> >>>

Can you reply in plain-text next time?  Your html e-mails are very
broken for me and really hard to read.  Everything is tabbed over
randomly and the e-mails don't appear to be in the correct order.


How did you start this python console?  If you can start the console
you should be able to run scripts just fine.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find Elements in List That Equal A Specific Value

2010-05-12 Thread Luke Paireepinart
On Wed, May 12, 2010 at 1:22 PM, bob gailer  wrote:
> On 5/12/2010 1:58 PM, Su Chu wrote:
>>
>> I have three lists, one with unique values (list 1), one a sequence of
>> values that are not necessarily unique (list2), and a shorter list with the
>> unique values of list 2 (list 3). List 1 and List 2 are of equal lengths.
>>
>> What I would like to do is find and sum the elements of list 1 given its
>> corresponding element in list 2 is equal to some element in list 3.
>>
> result = []
> for n in list3:
>  result.append(sum(list1[x] for x in range(len(list1)) if list2[x] = n)
>
bob,
your parenthesis are unbalanced and you put an assignment instead of a
comparison...

I'd probably do this with a dictionary.
d = {}
for i, val in enumerate(list1):
d[list2[i]] = val + d.get(list2[i], 0) # or whatever the default
get code is.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] raw_input a directory path

2010-05-12 Thread Luke Paireepinart
On Wed, May 12, 2010 at 2:44 PM, Spencer Parker  wrote:
> I have a search and replace script that I am having the user put in the
> directory path as raw_input.  The problem lies when I run the script it
> doesn't pick that up for some reason.  Is there an appropriate way to take a
> directory path as input? This is on windows...

Well I could speculate about all the different problems this could be caused by,
or you could provide more detail.
Let's go with that.

How do you know the script doesn't input the data correctly?
and why do you think it doesn't?
Where is the code that performs this?
How are you running the script?

Directory path should be no different than any other string.
I'm guessing it has to do with backslashes but I'll wait until you explicate.
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating distribution lists in outlook

2010-05-12 Thread Luke Paireepinart
On Wed, May 12, 2010 at 12:44 PM, Pirritano, Matthew
 wrote:
> Pythonistas,
>
> I’m trying to find a way to get data into outlook. Specifically to create
> distribution lists.

Have you considered looking into Outlook's Import feature for address
books?  It may be possible to import data from csv's already, and you
may be able to structure these into groups in a clever way and avoid
almost all of the work of interfacing Outlook to your program.

Depending on the scale / frequency of this project it might not be
feasible, but it's something to consider.

-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating distribution lists in outlook

2010-05-12 Thread Luke Paireepinart
On Wed, May 12, 2010 at 6:20 PM, Pirritano, Matthew
 wrote:
> That's the way we've been doing it. The issue, and inspiration for
> pythonification is that the list has 1000+ emails. Outlook only allows
> about 50 per list, which leads to the need to create 20+ separate lists,
> which takes a considerable amount of time.
>
Can't you import them all at once though? from a single file? rather
than 20 separate ones? (i.e. they would still be 20 lists but you'd
only have to go through the import process once.)

Are you trying to automate Outlook to send the e-mails, or just to
load in the list?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating distribution lists in outlook

2010-05-12 Thread Luke Paireepinart
On Wed, May 12, 2010 at 6:32 PM, Pirritano, Matthew
 wrote:
> Here's the thing. You can import them all at once. But then you have
> 1000+ contacts in one contacts folder. When you create the distribution
> lists a number get cut off if you try to put too many into the list. But
> there is no indication of how many went into the list. And there are not
> row numbers or anything like it in the contacts folders. So you'd have
> to keep in mind how far you got and then choose the next set, and it
> would be way to labor intensive if you were to count to 50 and then do
> that again. It's easier to create 20 separate files and make
> corresponding lists.  But still takes a while.

Pardon me for continuing not to address your specific question, but
this seems like something that businesses would commonly run into and
I'd be very surprised if there's not a way around this already.
Is there really no way to have a group of more than 50?  Have you
tried creating distribution lists based on contact groups?  If this is
possible you could automatically add all contacts to one specific
group.

I really think there's a simple solution if you look into it, but I
don't have outlook, I use Thunderbird.

Are you able to use a plugin to perform the work or is that against
your company's policies?

I just don't see automating with COM being the cleanest / most robust
approach, but if you really want to try it hopefully we can help if
you run into any python-specific issues!
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Design Question: File Object used everywhere

2010-05-13 Thread Luke Paireepinart
On Thu, May 13, 2010 at 11:49 PM, Jan Jansen  wrote:
> Hi there,
>
> I'm working on a code to read and write large amounts of binary data
> according to a given specification. In the specification there are a lot of
> "segments" defined. The segments in turn have defintions of datatypes and
> what they represent, how many of some of the data values are present in the
> file and sometimes the offset from the beginning of the file.
>
> Now I wonder, what would be a good way to model the code.

Personally I would just create a class that inherits from object (btw
I don't think you should have empty parenthesis after your classname,
I believe you should explicitly say object so it's clear what you're
inheriting from) and just implement the generic file object methods
(in this case read() and close() is probably all you'd need.)
that way you can pass it to other classes if you need to.
Basically the pythonic way is to make it as generic as possible and to
exploit duck typing so that other classes don't need to know how
you're actually implementing your reading/writing behind the scenes.

I'm not sure if that's acceptable (or even desirable) in this
particular situation though.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Luke Paireepinart
On Fri, May 14, 2010 at 12:55 PM, Gary Koskenmaki  wrote:
> Hi,
>
> I'm new to any kind of application development, but have done some
> python scripting.
>
> What I'm doing is creating an application for a non-profit social
> services organization that will allow them to track the services they
> give their clients.
>
> My plan so far was to use tabs for the different functions of the
> application such as entering data into the database, viewing data, and
> running reports.  I'm running into problems combining tabs with multiple
> data fields and buttons.  I can create multiple fields(text boxes) with
> wxFrame and wxPanel, but when using wxNotebook to create tabs only the
> last text box in each tab shows up.  Say I have 3 text boxes, only the
> third one shows up.  If I comment it out the second one shows up.  I
> have a very similar problem with buttons.
>

I have never used this tabbing before, but I'm guessing that you have
to catch the tab switching event and manually set the active panel
that the tab widget is displaying.
Something like (pseudocode)

panel1 = MyPanel()
panel2 = MyPanel2()
tabber = WxNotebook()

def myfunc(event):
if event.name == 'tab1':
tabber.set_active(panel1)
else:
tabber.set_active(panel2)

tabber.register_callback('tabswitch', myfunc)

That's purely a guess though.

>
> Am I going about creating this application interface in the most
> difficult way?  Is there a better/easier way to create multiple
> application views in the same window?  Can anyone recommend good books,
> tutorials, etc...?
>

Personally I like Qt more than WxWindows.  In fact I like TK more as
well, but tkinter looks kinda crappy and non-native on almost every
platform.
There are lots of resources for Qt, and for pyQt specifically.

This is probably not the right place to ask this question though,
we're more for general Python questions.  May be better to ask on a
wxpython list.

HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Luke Paireepinart
Thanks for that info, Alan! It's pretty awesome to have support for a
gui that looks native and is also included with Python by default.
I'll check it out soon.

On 5/14/10, Alan Gauld  wrote:
>
> "Luke Paireepinart"  wrote
>
>> well, but tkinter looks kinda crappy and non-native on almost every
>> platform.
>
> Check out the new themed widgets in Tkinter for Python 2.7 and 3.1
> They use native platform widgets so don't just look like the native
> interface they are the native interface...
>
> Hello world example here:
>
> http://www.testingreflections.com/node/view/8382
>
> Module doc here
>
> http://docs.python.org/dev/library/ttk.html
>
> And the Tk tutorial with screenshots here:
>
> http://www.tkdocs.com/tutorial/onepage.html
>
> And a new TKGui builder that includes support for Python - I haven't tried
> this
> yet...
>
> http://puretkgui.sourceforge.net/
>
> I'm hoping to add a page to my tutorial on the use of both Tix and ttk in
> the new Python v3 version, if I ever get time to finish it!
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning python using Michael Dawson's book

2010-05-17 Thread Luke Paireepinart
I don't see any printing of dashes whatsoever.
can you explain in more detail what output you're getting, how it's
different from what you expected, and why you think that happened?

On 5/17/10, Peter  wrote:
> Hello,
> I am at the very beginning of learning Python. If anyone is familiar
> with Michael Dawson's book: "Python Programming for the Absolute Beginner"
> The following script (according to the book) should create "block
> lettering" created by dashes and vertical lines. If I could show a
> picture of it I would. I do not get the same result as the book.
> Thank you for any input.
> Peter
>
>
> The script goes like this:
>
> ---
>
> #Game Over- Version 2
> #Demonstrates the use of quotes in strings
>
> print("Program 'Game Over' 2.0")
>
> print("Same", "message", "as before")
>
> print("Just",
>  "a bit",
>  "bigger")
>
> print("Here", end=" ")
> print("it is...")
>
> print(
> """
> """
> )
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Learning python using Michael Dawson's book

2010-05-17 Thread Luke Paireepinart
Forwarding. Peter use reply-all don't reply offlist please.

-- Forwarded message --
From: Peter 
Date: Mon, 17 May 2010 10:08:47 -0400
Subject: Re: [Tutor] Learning python using Michael Dawson's book
To: Luke Paireepinart 

Hi,
The result in the book has lettering like the following:
_____   __
|||| ||
||__|| ||
|__ |  ||
|||| ||
|__||__| |__|





On 5/17/2010 9:54 AM, Luke Paireepinart wrote:
> I don't see any printing of dashes whatsoever.
> can you explain in more detail what output you're getting, how it's
> different from what you expected, and why you think that happened?
>
> On 5/17/10, Peter  wrote:
>
>> Hello,
>> I am at the very beginning of learning Python. If anyone is familiar
>> with Michael Dawson's book: "Python Programming for the Absolute Beginner"
>> The following script (according to the book) should create "block
>> lettering" created by dashes and vertical lines. If I could show a
>> picture of it I would. I do not get the same result as the book.
>> Thank you for any input.
>> Peter
>>
>>
>> The script goes like this:
>>
>> ---
>>
>> #Game Over- Version 2
>> #Demonstrates the use of quotes in strings
>>
>> print("Program 'Game Over' 2.0")
>>
>> print("Same", "message", "as before")
>>
>> print("Just",
>>   "a bit",
>>   "bigger")
>>
>> print("Here", end=" ")
>> print("it is...")
>>
>> print(
>>  """
>>  """
>>  )
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Successfully trapping the [505 file not found] error

2010-05-26 Thread Luke Paireepinart
>
> What follows is the exception handling snippet:
> ## --
> except ftplib.error_perm, e:
>    msg = "Couldn't get %s  %s" % (fname,str(sys.exc_info()[1]))
>        log.add(msg)
>        more-code-follows
> ## --
> When the code above is successful, the application simply
> logs the exception and continues.
> When the code above fails the traceback is as follows:
>

Are you sure you aren't doing anything with the ftp object in the
"more code follows"?
You are probably creating another error of the same type while
processing your exception, so the second one doesn't get caught.

like this (except with ftp obviously):
try:
f = open('in.txt')
except IOError:
y = open('log.txt', 'w')
y.write('failed!')
y.close()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list of dicts <-> dict of lists?

2010-05-28 Thread Luke Paireepinart
> I'm new to python, so i don't know if this is important, or what it means at 
> all.  I looked in setup.py, and it didn't tell me anything.  What does it 
> mean by "the necessary bits" were not found?

Not really sure, but in the future please create a new e-mail to
tutor@python.org rather than hijacking a thread.  And don't just hit
"reply" and delete the contents of a different e-mail, you have to
create an entirely new message.  Otherwise your message will get
threaded with that other message's thread in certain e-mail clients.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHON ON NOKIA E71

2010-05-30 Thread Luke Paireepinart
On Sun, May 30, 2010 at 1:17 PM, Dipo Elegbede  wrote:
> Hi all,
> Pls does anyone know whether I can install python and code on my Nokia E71?
> I have full access to computer at my office but not at home. This is
> creating a serious break in my flow of study.
> With python on my phone,I can learn and code on the fly.
> Already,I read Alan Gauld's note from my phone browser but I need to
> start doing stuffs with my phone.
> If you got an idea or the link, pls bring it on.
> Thanks and Best regards,

Yep I've got Python and Pygame on my E71 so it's definitely possible.
You could've probably found the reference on Google faster than
posting here and waiting for a reply.

Good luck, it's a lot of fun having Python on your phone!
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Better construct? (was no subject)

2010-06-12 Thread Luke Paireepinart
>
>> ## Can someone suggest a pythonesque way of doing this?
>>
>>
>> def getid():
>>    response  = raw_input('prompt')
>>    if response not in [ "", "y", "Y", "yes"] :
>>        getid()    # ouch
>>    print "continue working"
>>    # do more stuff
>>    # do more stuff
>>
This seems like really strange behavior.  If the response is wrong,
you will then have another instance of getid, then if they get the
response correct, you will execute your code twice!  Was that really
your intent?
I think what you really want is:
def getid():
valid = False
while not valid:
response = raw_input('prompt')
valid = response.strip().lower() in ["", "y", "yes"]

>One improvement - response.lower().startswith("yes") will cover all your cases.

Am I misunderstanding? They appear to have different behaviors.
>>> x = ""
>>> y = ["", "y", "Y", "yes"]
>>> x not in y
False
>>> x.lower().startswith('yes')
False
>>> x = "yes"
>>> x not in y
False
>>> x.lower().startswith('yes')
True
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running external commands from Python

2010-06-25 Thread Luke Paireepinart
Subprocess module is the preferred strategy when You want to communicate with 
the command you're running. If not, you can use os.system.

Sent from my iPhone

On Jun 25, 2010, at 5:46 PM, Randy Kao  wrote:

> Hi all,
> 
> I'm a newbie to Python (switching from Perl) and had a question about the 
> best way to run external commands in Python.
> 
> In doing some reading I'm confused about which is the best way to accomplish 
> this.
> 
> With Perl, the way I went about running commands was by opening a filehandle 
> and parsing / manipulating the data.
> 
> i.e. open(XYZ, "ls -la *");
> 
> In trying to do this in Python, I think I've read a couple ways to do this.
> 
> through: os.popen, os.popen2, os.popen3, os.system, commands.getoutput()
> 
> I might not be understanding when to use which of these correctly and was 
> hoping for some feedback from this more experienced group.
> 
> Thanks in advance!
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running external commands from Python

2010-06-25 Thread Luke Paireepinart
On Fri, Jun 25, 2010 at 7:48 PM, David Hutto  wrote:
> On Fri, Jun 25, 2010 at 8:16 PM, Steven D'Aprano  wrote:
>> On Sat, 26 Jun 2010 08:46:17 am Randy Kao wrote:
>>> Hi all,
>>>
>>> I'm a newbie to Python (switching from Perl) and had a question about
>>> the best way to run external commands in Python.
>> [...]
>>> through: os.popen, os.popen2, os.popen3, os.system,
>>> commands.getoutput()
>>
>>
>> os.system is the oldest way, and it's pretty much obsolete.
>
>
> Not to hijack  this thread, but why would accessing, what I(newbie
> ++1) know as the direct interface from python to the machine you're
> on, be obsolete? Isn't this the direct way to access your machine
> through the python 'application', if I'm using this term right?
>

He means that in most cases what you want to do is probably capture
the stdin & out.  it's not obsolete, it's just not that common of a
case. I'm not sure why he used that term.  Most people tend to use
popen because it's more useful.  However, os.popen _is_ obsolete, or
at least discouraged; the correct module to use is the subprocess
module, as I mentioned earlier.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running external commands from Python

2010-06-25 Thread Luke Paireepinart
On Fri, Jun 25, 2010 at 8:43 PM, David Hutto  wrote:
> On Fri, Jun 25, 2010 at 9:37 PM, Randy Kao  wrote:
>> Thanks for the great and quick feedback from everyone!
>> That definitely clears things up.
>> -Randy
>
> And I was like...me too.

Just to clarify, it looks like subprocess is intended to replace ALL
of the previously-mentioned commands, even os.system.  So in a sense
they are all obsolete.
Please see http://docs.python.org/library/subprocess.html for more information.

Also, this list is awesome.  Make much use of it.  There haven't been
enough posts lately!
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function returns 'None'

2010-07-11 Thread Luke Paireepinart
I think the new version is harder to understand.

Sent from my iPhone

On Jul 11, 2010, at 10:43 AM, Nick Raptis  wrote:

> On 07/11/2010 06:28 PM, Nick Raptis wrote:
>> 
>> def recursfac(x,carryover=1):
>>print 'x:',x,'carryover:', carryover
>>if x > 1:
>>carryover *= x
>>carryover = recursfac(x-1, carryover)
>>return carryover
>> 
>> And this returns
>> x: 3 carryover: 1
>> x: 2 carryover: 3
>> x: 1 carryover: 6
>> 6
>> 
>> Done!
>> 
> 
> Also, I realized that my final code may be tough to decipher now.. A nicer 
> way to write it would be (the functionality is still exactly the same):
> 
> def recursfac(x,carryover=1):
>print 'x:',x,'carryover:', carryover
>if x > 1:
>carryover *= x
>result = recursfac(x-1, carryover)
>else:
># done with recursion, start our way up
>result = carryover
>return result
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function returns 'None'

2010-07-11 Thread Luke Paireepinart
On Jul 11, 2010, at 11:14 AM, Nick Raptis  wrote:

>> 
>> 
>> 
> 
> Also, another preference of mine, would you be kind enough to answer to the 
> list and cc the original poster if you can? Doing it the other way around 
> breaks my (quite stupid I admit) filters, and perhaps others' too.
That's the default email setup for the iPhone. I agree it's silly but it seems 
quite difficult to modify the fields. I see your point about the variable names 
but if it's at least fairly obvious what you're intending to do it seems like a 
bit of a waste to have an extra variable and else block. But you know, potato 
potato. It's negligible from a performance standpoint, it's really just a 
question of readability. Do what makes you ( and the people who will read your 
code) happy.
-luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Luke Paireepinart
You already know how to store multiple vars -- use lists! Just create a blank 
one before your loop and append() to it. Also you might think of a generic way 
to do this without relying on separate variables for each aisle, what if your 
store has 30 aisles? Hint: lists can contain any python object, even other 
lists.

Sent from my iPhone

On Jul 14, 2010, at 2:05 PM, Eric Hamiter  wrote:

> Follow-up question: My code is now this:
> 
> aisle_one = ["chips", "bread", "pretzels", "magazines"]
> aisle_two = ["juice", "ice cream"]
> aisle_three = ["asparagus"]
> 
> def find_groceries():
>grocery_list = open("grocery_list.txt", "r")
>for line in grocery_list.readlines():
>line = line.strip()
>if line in aisle_one:
>first_run = "%s" % line + " - aisle one.\n"
>elif line in aisle_two:
>second_run = "%s" % line + " - aisle two.\n"
>elif line in aisle_three:
>third_run = "%s" % line + " - aisle three.\n"
>else:
>out_of_luck = "%s" % line
>print first_run, second_run, third_run
>print "I couldn't find any %s. Add it to the database. \n" % out_of_luck
>grocery_list.close()
> 
> find_groceries()
> 
> 
> I can see that the variables first_run, second_run and third_run are
> writing over themselves while looping, which is logical, but this is
> not what I want. If I simply print them immediately instead of storing
> them as variables, all items will print, but not in the order I wish.
> The ultimate goal of the program will be to sort the items based on
> aisle locations. Is there an efficient way to do this?
> 
> I think I want some kind of incremental counter going on in the loop
> to prevent them from overwriting themselves, or a way to store
> multiple variables, but I'm not sure how to do that.
> 
> Thanks for any ideas. This list and all its participants are super
> helpful-- I'm very appreciative.
> 
> Eric
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] now = ctime()[11:20]

2010-07-17 Thread Luke Paireepinart
If you are asking how to get a variable to call a function each time it's 
accessed... Well that's kind of a weird request. I know you can create 
properties in a class that act like variables but you can do whatever you want 
behind the scenes, like calling the now() function on each access. A much more 
clear way to do this would be to create a function that calls the now function 
and just call your function whenever you want the value. Is there a specific 
reason why you would prefer to solve this without having to type 2 extra 
characters () and in turn make your code more readable and logical? The problem 
with the approach you hint at is that then the function call is implicit. What 
if someone else wanted to use your variable in a tight loop? They don't 
probably expect or want your variable to automatically update itself.

Also are you aware of the timeit module for dete

Perhaps I misunderstood your intent.

Sent from my iPhone

On Jul 17, 2010 at 1:32 AM, "Richard D. Moores"  wrote:

> Please see 
> 
> Foolishly, without thinking it through, I expected the 2 prints to
> show different times. I understood right away why they were identical,
> but then I began to wonder how to create an "alias" for
> "ctime()[11:20]" so I wouldn't have to keep typing or pasting it.
> "now" would be fine. But how to get it to execute ctime()?
> 
> Thanks,
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] now = ctime()[11:20]

2010-07-17 Thread Luke Paireepinart
Sorry the iPhone email client is terrible. It sent the previous email before I 
was done writing it. Anyway, the timeit module is available whenever you want 
to profile something and determine how long it takes to run.

Sent from my iPhone

On Jul 17, 2010, at 1:32 AM, "Richard D. Moores"  wrote:

> Please see 
> 
> Foolishly, without thinking it through, I expected the 2 prints to
> show different times. I understood right away why they were identical,
> but then I began to wonder how to create an "alias" for
> "ctime()[11:20]" so I wouldn't have to keep typing or pasting it.
> "now" would be fine. But how to get it to execute ctime()?
> 
> Thanks,
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Luke Paireepinart

On Jul 17, 2010, at 7:19 PM, "Richard D. Moores"  wrote:

> I don't fully understand your "you always have two [chunks] in memory
> at once". Does that take care of the overlap I think I need? I don't
> want you or anyone to give me the the whole answer, but could you
> clarify a bit about keeping 2 chunks in memory? Let's say the chunks,
> in order, and without overlap, are A, B, C, D, E, ...  So I'd have AB
> to search, then BC, then CD, then DE, ... ? But then what if I find an
> instance of, say, my father's birthdate in B when searching AB. Then
> I'd find the same instance again in BC. How do I prevent that from
> counting as 2 instances?

Imagine you have a series of Buildings in a block, and you are checking to see 
if a series of 5 windows in a row is on ( even between buildings). You start at 
one end of the block and you check the first five windows. If they are all on, 
you have found a match. If not, you move forward one window. Now repeat. After 
a few repetitions you will end up at the border between two buildings, and 
after a few more you will be looking exclusively at the 2nd building. Then 
after a few more you will be looking at the 3rd building and so on.

But are you ever looking at more than one building at a time? Yea but only 
adjacent buildings and only for 4 steps. Once, when you have 4 windows from the 
first, 1 from the second, again for 3 windows from the first, then 2 and then 1.

The way this translates into an algorithm is that instead of discarding your 
old set of data as soon as you need to load another set, you hold onto it long 
enough to get all the way engaged with that second set, and from there you can 
free up the previous block's memory and move forward. And since you are using a 
"sliding window" approach you shouldn't ever find one result twice. Although 
note that if you overlap your searches as I said earlier, you can run into some 
matching situations that are interesting. Say you search for 55 and your string 
is 1827355513. You'll find 55 twice even though there are only 3 fives in the 
search string. Just something to keep in mind.

Hope that helps!
-luke___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] searching for multiple strings in line.starswith()

2010-07-19 Thread Luke Paireepinart
You are using Line.startswith incorrectly, read the docs on it and see if you 
can figure out your problem an key us know. Pay attention to the parameters it 
takes and the values it returns.

Sent from my iPhone

On Jul 19, 2010, at 11:18 AM, Bala subramanian  
wrote:

> Friends,
> I have to extract the line from a file that does not contain a set of strings 
> in the start of the line, i wrote the following code.
> 
> for index, line in enumerate(myvar.split('\n')):
> if line.startswith('') not in ['#Cluster','#Centroid','#End']:
> line=line.split()
> print line
> 
> The code works without error but it seems that the condition is not applied. 
> What is the correct way of searching for multiple strings at the start of a 
> line.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] has it gone quiet or is it just me?

2010-07-21 Thread Luke Paireepinart
Not sure Alan.
I haven't gotten any messages either, but this one came through just fine.
-Luke

On Wed, Jul 21, 2010 at 12:55 PM, Alan Gauld  wrote:
> I haven't had any tutor messages in 2 days.
> Do I have a problem or are things just very quiet suddenly?
> The archive isn't showing anything either which makes me suspicious.
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound libraries?

2010-07-22 Thread Luke Paireepinart
You can access openal through either pyglet or pygame I believe, and definitely 
thru panda3d. That would allow you to have true 3d sound positioning and I 
believe openal can automatically Doppler too, not sure though. Let us know what 
you go with or if you have questions.

Sent from my iPhone

On Jul 22, 2010, at 6:49 PM, Alex Hall  wrote:

> Hi all,
> I am curious. If I wanted a library that would let me play sounds at
> specific positions in the stereo field, then update that position as
> the user "moved" so that it would seem to be a fixed reference point,
> what would I use? For example, say the left/right arrows move you left
> and right. In the center of your stereo field you hear a sound, say a
> bell. As you press the arrow keys, the sound moves, or rather, you
> move but the sound stays the same. Pysonic looks like the perfect
> answer, but it seems to require python2.3, and I am using 2.6. Are
> there any other conprehensive sound libraries that would allow for
> dynamic positioning of sound, doplar effects, volume control, and so
> on?
> 
> -- 
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


  1   2   3   4   5   6   7   8   9   >