Re: [Tutor] Offtopic observation

2006-06-07 Thread Jonathon Sisson
Kent Johnson wrote:
>> From: Danny Yoo <[EMAIL PROTECTED]>
>> On Wed, 7 Jun 2006, doug shawhan wrote:
>>
>>> This marks the third time this week I have been typing in a question for 
>>> the group, and have made the answer apparent just by trying to explain 
>>> my question clearly.
>> Yes.  *grin*  It's a very powerful technique.  Writing does this for me as 
>> well.
> 
> For me it's often talking. I have a friend in the office I go to when I am 
> stuck on something. He's a very powerful listener - often by the time I am 
> done describing the problem and the available options I have settled on an 
> answer.
> 
> Kent
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

I want one of those...hahaha...someone who would listen long enough for
me to settle on an answer on my own?  God, you're a lucky person.  If I
so much as shape my mouth like the word "computer" is going to come out,
my wife runs for cover...my friends do their best, but most of them
aren't great listeners so we end up getting off topic and never do find
a solution.  My daughter listens, but I have to wait for her to start
pre-school for hope of any real response.  Consider yourself quite
lucky, Kent.

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


Re: [Tutor] An Introduction and a question

2006-06-10 Thread Jonathon Sisson
Michael Sullivan wrote:
> Here's the situation:  My wife likes to play the game Chuzzle, found at
> Yahoo Games.  We use primarily Linux, however Chuzzle is written as an
> ActiveX control, which only works on Windows.  I have not been able to
> get Internet Explorer to work correctly through Wine, 

This might not be a Python topic, but I figured I'd respond with what I
know on this particular subject...

ActiveX can be run in Linux using the WINDOWS version of Mozilla in Wine
and a little bit of coaxing as per this HOWTO on the Gentoo Forums (make
sure you install the ActiveX control in Wine...):

http://forums.gentoo.org/viewtopic-t-246098-highlight-warcraft.html

World of Warcraft uses ActiveX in it's patch updater, and although I've
never personally run it I've had many people tell me this method works.
 Now if I could just figure out how to convince my wife to try Linux (as
you apparently have done) then I'd be set...kudos to you on that.

Jonathon

so I determined to
> write a Chuzzle-like game (with many of my own enhancements) for Linux.
> I've been playing around with some Pygame examples lately, and thought
> that I'd try writing the game in Python (I've been meaning to learn
> Python for years, but just never got around to it.)  Today I started on
> writing the game.  I've decided (at least for now) to call my version,
> LinePuzzle.  For those of you unfamiliar with Chuzzle, here's the basic
> concept:  There are individual pieces of different colors arranged on a
> grid.  The pieces can be moved on a line either vertically or
> horizontally.  The object of the game is to position three similarly
> colored pieces ajacent to each other.  At this point the three pieces
> will disappear, and the pieces above them will fall to take their place.
> As the levels progress, locks are added so that the player cannot move a
> locked piece either horizontally or vertically.  The game is over when
> no more pieces can be removed.  
> 
> I started my script by creating a class called LinePuzzlePiece which
> represents a single coloured piece.  I wanted a random colour chosen
> from a list to be assigned to the piece, and then to prove that I had it
> set up correctly, I wanted to call a method that would print out the
> color of the piece.  Here is my code:
> 
> #!/usr/bin/env python
> 
> import random
> import time
> import math
> 
> class LinePuzzlePiece:
>"""This class defines a single playing piece for LinePuzzle"""
>def __init__(self):
>   seed(time)
>   index = int(math.floor(uniform(1, 10)))   colorlist = ["red",
> "blue", "green" "yellow", "purple"]   self.color = colorlist[index]
> 
>def printcolor():
>   print self.color
> 
> mypiece = LinePuzzlePiece
> mypiece.printcolor
> 
> 
> I saved the script and made it chmod +x.  However, when I run it, I get
> this:
> 
> [EMAIL PROTECTED] ~ $ ./linepuzzle.py
> [EMAIL PROTECTED] ~ $
> 
> Now, I'm no expert, but I really think something should have been
> printed, if even a blank line.  What am I doing wrong here?  Why is
> nothing printing?  Is my printcolor method even being called
> successfully?
> -Michael Sullivan-
> 
> 
> 
> ___
> 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] An Introduction and a question

2006-06-10 Thread Jonathon Sisson
've triedMichael Sullivan wrote:
> On Sat, 2006-06-10 at 03:27 +0100, Jonathon Sisson wrote:
>> Michael Sullivan wrote:
>>> Here's the situation:  My wife likes to play the game Chuzzle, found at
>>> Yahoo Games.  We use primarily Linux, however Chuzzle is written as an
>>> ActiveX control, which only works on Windows.  I have not been able to
>>> get Internet Explorer to work correctly through Wine, 
>> This might not be a Python topic, but I figured I'd respond with what I
>> know on this particular subject...
>>
>> ActiveX can be run in Linux using the WINDOWS version of Mozilla in Wine
>> and a little bit of coaxing as per this HOWTO on the Gentoo Forums (make
>> sure you install the ActiveX control in Wine...):
>>
>> http://forums.gentoo.org/viewtopic-t-246098-highlight-warcraft.html
>>
>> World of Warcraft uses ActiveX in it's patch updater, and although I've
>> never personally run it I've had many people tell me this method works.
>>  Now if I could just figure out how to convince my wife to try Linux (as
>> you apparently have done) then I'd be set...kudos to you on that.
>>'ve triedi 
>> Jonathon
> 
> My wife says that she actually prefers Linux over Windows.  The only
> thing we use Windows for is playing Civilizations II and The Sims,
> although she also uses it for playing Internet games that don't work on
> Linux.  She's said that if I can make Linux versions of those games she
> plays on Windows, she won't use Windows at home anymore.  When I first
> started with Linux, she was kinda iffy about it, but now she loves it.
> We've only used it since fall of 2003...
> 
> 

Part of my reasoning behind learning Python is that Python used so
heavily in the Gentoo Linux package management system "Portage."  I love
portage because of it's flexibility and configurability, and I hope
someday to make a contribution back to the OS that really got me hooked
on Linux.  (I started out with RedHat around May of 2002, but I grew
tired of it pretty quickly.  I moved from there to try out SuSE,
Slackware, Mandrake, Fedora (after giving RedHat a break for a few
months), and a few others (haven't tried out Debian...I hear it's really
nice, too), but when I saw Gentoo's optimization and configuration
capabilities, I was in for life...).

Therein lies the difference...I'm an efficiency nut (no I really do not
mind compiling the entire OS from source, as long as I can compile it
*exactly* how I want, using *only* what I want), and my wife just wants
to kick people's a$$es online.  She got a bad first impression of Linux
from the start because I was constantly tweaking (and breaking) my Linux
system, so the chances of her using Linux are rather slim, even though
as I progress with my Computer Science degree, I break my Linux system
less and less...hahaha.

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


Re: [Tutor] help

2006-08-24 Thread Jonathon Sisson
Hi Mike,

I'm not sure I'm understanding exactly what it is you're looking for
here, but from what I can tell you're looking for something such as:

num(220, 330) #for example
input a range of 10 # again, for example

which would result in an output of 0, 660, 1320 and 1980 (because
these four numbers are common to both kl and ll).

If this is indeed the case, then you need to replace the "while f hello i need a little help with a common multiple module i am haveing
> problems with the best i can get it is to show the least common multiple i
> think the problem is eather the and command ot the if command
>
># finds common multiples
> def nums(a,b): # assigns numbers to a and b
> print "enter range"
> c = input(">")
> both=[]
> e=-1
> f=-1
> kl=[]
> ll=[]
> while e e=e+1
> k=a*e
> l=b*e
> print a,"X",e,"=",k,"   ",b,"X",e,"=",l
> kl.append(k)
> ll.append(l)
> while f f=f+1
> if f in kl and f in ll:
> both.append(f)
> print both
>
> any help would be great
>
>
>
> ^_^"  s33 y4
>
> _
> Call friends with PC-to-PC calling -- FREE  
> http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
>
> ___
> 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] help

2006-08-24 Thread Jonathon Sisson
Gah!

Seems I sent that reply before stepping through my code a bit...
The last section of that code should be:

else:# kl and ll contain the same number here
both.append(kl[indexK])
if indexK < indexL: # this block is needed so we
indexL = indexL + 1 # don't enter an endless loop...
else:
indexK = indexK + 1

The way I had it set up before (see below) always increments indexL.
Not a problem for this particular instance, but definitely shabby 
programming...oops...

Jonathon


Hi Mike,

I'm not sure I'm understanding exactly what it is you're looking for
here, but from what I can tell you're looking for something such as:

num(220, 330) #for example
input a range of 10 # again, for example

which would result in an output of 0, 660, 1320 and 1980 (because
these four numbers are common to both kl and ll).

If this is indeed the case, then you need to replace the "while f > hello i need a little help with a common multiple module i am haveing
> > problems with the best i can get it is to show the least common multiple i
> > think the problem is eather the and command ot the if command
> >
> ># finds common multiples
> > def nums(a,b): # assigns numbers to a and b
> > print "enter range"
> > c = input(">")
> > both=[]
> > e=-1
> > f=-1
> > kl=[]
> > ll=[]
> > while e > e=e+1
> > k=a*e
> > l=b*e
> > print a,"X",e,"=",k,"   ",b,"X",e,"=",l
> > kl.append(k)
> > ll.append(l)
> > while f > f=f+1
> > if f in kl and f in ll:
> > both.append(f)
> > print both
> >
> > any help would be great
> >
> >
> >
> > ^_^"  s33 y4
> >
> > _
> > Call friends with PC-to-PC calling -- FREE  
> > http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>   
--- Begin Message ---
Hi Mike,

I'm not sure I'm understanding exactly what it is you're looking for
here, but from what I can tell you're looking for something such as:

num(220, 330) #for example
input a range of 10 # again, for example

which would result in an output of 0, 660, 1320 and 1980 (because
these four numbers are common to both kl and ll).

If this is indeed the case, then you need to replace the "while f hello i need a little help with a common multiple module i am haveing
> problems with the best i can get it is to show the least common multiple i
> think the problem is eather the and command ot the if command
>
># finds common multiples
> def nums(a,b): # assigns numbers to a and b
> print "enter range"
> c = input(">")
> both=[]
> e=-1
> f=-1
> kl=[]
> ll=[]
> while e e=e+1
> k=a*e
> l=b*e
> print a,"X",e,"=",k,"   ",b,"X",e,"=",l
> kl.append(k)
> ll.append(l)
> while f f=f+1
> if f in kl and f in ll:
> both.append(f)
> print both
>
> any help would be great
>
>
>
> ^_^"  s33 y4
>
> _
> Call friends with PC-to-PC calling -- FREE  
> http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



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


[Tutor] Java: (and python ?) nearer measles than coffee

2006-09-11 Thread Jonathon Sisson
Hrmmm...my opinion is that you shouldn't waste your time with Java
(sorry to any Java coders on this list).  It's entirely too automated
for my tastes (automatic garbage collection, transparent pointers,
etc...).  To quote an unknown author who was quite the anti-OOP
programmer, "it made me want to throw a java.f***ThisException".

So why, might you ask, am I bothering learning Python?

Well, at first I was looking for a powerful scripting language to
prototype with.  You know the routine...whip up a quick and dirty
"version 0.1" and let the customer see what's in store, test layouts,
algorithms, design ideas, etc...

Reason I use Python #1:
But then I noticed something.  Python runs on my wife's Windows
machine...and my Linux machine...and my OpenBSD machine...and ...etc...  The real catch for me was
OpenBSD support.  Find a thorough java runtime for OpenBSD (I last
looked probably a year or two ago, so correct me if I'm wrong on this),
and perhaps I'll try it out, but until then, Python is my choice when I
need code that will run on multiple OS's.

Reason I use Python #2:
I'm not trying to flatter anyone, seriously, I'm not...but this list is
another reason Python has been a favorite of mine.

Reason I use Python #3:
I am a strong advocate of Open Source Software and the GPL.  If Sun
truly supported Open Source, then the OpenBSD team would have the specs
for Java.

Reason I use Python #4:
If I want to code something in Java, give me a week.  For Python, give
me one night, perhaps two.  I prefer getting done so I can move on, ya know?

Anyways, those are the first few reasons I use Python.

Jonathon

Klaus Ramelow wrote:
> Sometimes I have also some  - or more - problems trying digesting python
> and feeling totally blocked.
>
> My programming experience (beginning at the card-reader era)
> main-frame, mini and micro :
> Bit / Byte / Word system-programming via switch-console followed by
> Assembler and commercial software using Basic, Cobol, Pascal and SQL.
>
> Mnemonic programming-language - in my understanding - can only be
> consisting of expressions near the human language.
> The best example for writing non-system-programms are
> Basic, Cobol (thanks to Alan) and SQL(especially Informix-SQL as full 
> language - not only for DB).
> Why should I waste time in learning a "language" like Java (or more
> positive: python) ?
> Nevertheless this Tutor Digest is most helpful, the number of questions
> / problems show:
> some more people are looking for a mnemonic-language which should
> optimized cross-compile to something with multiplatform-capability
> like Java.
> Please let me know, if I am entirely wrong.
>
> Klaus Ramelow
>
> ___
> 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] Python Course at Foothill College

2006-09-17 Thread Jonathon Sisson
I'll have to second that...my school is wrapped up with Java, C#, and
Scheme.  Python has all about ruined me for programming in other
languages, and I really wish Python was taught/allowed at my school. 
I'm currently working on a team for CSC 480 (Senior Project - Design
Phase) and we're forced to choke down Microsoft design models (I'm an
avid open source
advocate...(http://www.catb.org/~esr/writings/cathedral-bazaar/ for a
paper by Eric S. Raymond that, for me, hits the nail on the head).)

*sigh* Perhaps when I start grad school I'll be in a position to use my
favored language...until then I guess .NET wins.

By the way, CIS at my school is a hybrid between business and computer
science.  It's basically a lightweight computer science degree combined
with a lightweight business degree.  From a computer science standpoint,
it does cover the fundamentals (architectures, programming, data
structures, algorithms, etc...) but does not include the senior project
course series, advanced database admin, Windows admin, etc...

Luke Paireepinart wrote:
> Elaine wrote:
>   
>> If you would like to learn Python, Foothill College in
>> Los Altos Hills, CA  is offering a course starting
>> Mon. evening, 25 Sept. The course is designed for
>> students who are already familiar with some type of
>> programming. Here is the course description:
>>
>> CIS 68K  "INTRODUCTION TO PYTHON PROGRAMMING"  5 Units
>> 
>
> CIS is Computer Information Systems at my school.
> CIS is part of the business school and doesn't have much to do with 
> Computer Science.
> Is that how it is there as well?
> If so, do you have Computer Science courses in Python as well?
> (I don't live anywhere near CA, I'm just interested.)
> Wish my school used Python.
> -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


[Tutor] number game

2006-10-03 Thread Jonathon Sisson
Mike,

The algorithm you use is what causes the infinite loop (it cycles
through the same numbers repeatedly).  I've updated the code and I'll
post it here:

def num(number):
r=input("range >")
ran=range(r+1)
guess=r/2
print guess
guesses=1
min = 0
max = r
while guess!=number:
if guess < number:
min = guess
else:
max = guess
guess = (min + max) / 2
guesses += 1
print guess
print "i got the number",number,"in",guesses,"guesses"



mike viceano wrote:
> i wrote a program that guesses number in the most effective way i could 
> think of but i keep running into endless loops any help fixing it would be 
> great :)
>
> here it is:
>
>
> def num(number):
> r=input("range >")
> ran=range(r+1)
> guess=r/2
> print guess
> guesses=1
> while guess!=number:
> if guess < number:
> guess= ((r-guess)/2)+guess
> print guess
> guesses=guesses+1
> elif guess > number:
> guess= ((r-guess)/2)-guess
> print guess
> guesses=guesses+1
> print "i got the number",number,"in",guesses,"guesses"
>
>
>
> my only idea is to make it so it dosint re guess numbers but i would rather 
> just find out what is wrong
> and fix it
>
> _
> Express yourself - download free Windows Live Messenger themes! 
> http://clk.atdmt.com/MSN/go/msnnkwme002001msn/direct/01/?href=http://imagine-msn.com/themes/vibe/default.aspx?locale=en-us&source=hmtagline
>
> ___
> 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] Random Variable at root

2006-10-03 Thread Jonathon Sisson
Hugo,

You need to create an instance of the Root class before you can call
rootState in your final print statement.  Your code doesn't do this.  A
class is merely a template, something like blueprints to a house.  For
you to be able to unlock the front door (for instance), you need to
actually build a specific "instance" of the house first.  "313 Hillcrest
Lane" and "4214 Willowbrook Drive" might be two houses that have the
same blueprint, but maintain different states from each other because
they are different "instances" of class House.

To make this work, remove the final print statement and replace it with
this:

# instantiates ("builds") a copy of the Root class and names it "root"
root = Root(0)
print "The character state at the root is %0.f" % root._rootState

Note the change to the end of the print statement.  Your code has
rootState, mine has root._rootState (the specific instance of Root,
followed by the "dot" operator, followed by the attribute or method you
are trying to access).  I'm a bit confused as to whether you intended
_rootState to be a copy of the *original* value passed in, with
rootState maintaining a copy of the *current* value, or if that is a
typo.  Please elaborate.

Hope this helps clear up confusion (as opposed to creating more...heh).

Jonathon


halamillo wrote:
> Hello, 
>  I'm a really-green-to-python Biology Grad Student. I;m starting this
> code so I can assign either a 0 or a 1 at a root node that I will
> later evolve throughout a tree, but for some reason it is not printing
> the rootState value.  I know its probably a really stupid mistake, but
> I can't seem to work it out. Can anyone give me insight why? Thanks. 
>
> import random
> from random import random as rnd
> from math import exp
>
>
> class Root:
> """Single Node in a Tree"""
>
> def __init__( self, rootState ):
>
>
> self._rootState = rootState
>
> # random choice for root state from a list
> for i in range(1):
> rootState = random.choice([0, 1])
>
>
> def __str__( self ):
> """Root string representation"""
>
>
> return str( self._rootState )
> print "The character state at the root is %0.f" % rootState
>
>
> Hugo Alamillo
> Biological Sciences
> 265 Eastlick
> PO Box 644236
> Washington State University
> Pullman, WA 99164
>
>
>
>
>
> 
>
> ___
> 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] OT: Book(s) about linux

2006-10-05 Thread Jonathon Sisson
Hello Bernard...

Just to give you a pointer about Linux:  If you're new, Fedora and
Ubuntu are both relatively easy to learn, but powerful (I've never used
Ubuntu (or Debian, for that matter), but I hear that Ubuntu is a really
great distro).  Stay away from Slackware and Gentoo, at least until
you've had the chance to familiarize yourself with Linux.  I made the
mistake of attempting a stage 1 Gentoo install on a PII machine with
hardly any experience.  (Fortunately, the PII was so slow that I had
time to read the manual completely before each step).  It booted up fine
when I was done, but it was rough (even with extensive documentation ).

I'm not saying that Slackware and Gentoo are useless, as both are
*extremely* powerful OS's (Gentoo is my favorite OS other than OpenBSD).
 They do require quite a bit of knowledge just to get them installed,
however, and therefore are not good choices for someone just beginning
with Linux.

Jonathon


Python wrote:
> On Thu, 2006-10-05 at 11:33 -0400, Bernard Lebel wrote:
>> Hello,
>>
>> Sorry to use this list for such an OT subject. But I want to get hands
>> down with Linux, and am looking for a book or two on the subject.
>>
>> I'm looking for information about installation, configuration,
>> optimisation, and management of the Linux OS.
> 
> If you are new to Linux, you're likely to be best helped by a book that
> matches your distribution, e.g. "Ubuntu Linux" or "Ubuntu Unleashed".
> (Not to push you to Ubuntu; I'm running Fedora myself.)  These books
> provide shallow coverage of everything and will give the background
> needed to make good use of the system documentation.  They will also
> point you to yum, synaptic, smart or whatever package management system
> makes sense with your chosen distribution.  The package managers greatly
> simplify system administration.
> 
> There are books devoted to packages: SSH, Sendmail, DNS/Bind, Apache,
> Samba, etc. so you may need to get additional books depending on how you
> use your computer.  "Linux in a Nutshell" (mine is 5th edition) provides
> a useful reference.  There are also books like "Linux Debugging and
> Performance Tuning" which are more system oriented.  "Moving to the
> Linux Business Desktop" is useful for finding your way among all of the
> available desktop applications.  Linux is a pretty broad subject so
> there's a huge range of books from which to pick.
> 
>>
>>
>> Thanks
>> Bernard
>> ___
>> 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] from string to variable name

2006-10-05 Thread Jonathon Sisson
By "string variable that contains a name that I want to use as a
variablename" do you mean something like this:

myString = "rotationalSpeed"
rotationalSpeed = 4500

??

In Python a dictionary is an excellent solution to this problem.  The
only other way to accomplish this (to my knowledge) is in PHP (not
trying to steer you away from Python, just giving some info):

var myString = "rotationalSpeed";
$$myString = 4500;
echo $rotationalSpeed;

results in 4500.  This is called "variable variables" in PHP and it can
get hairy if done in a sloppy manner.

I'm going to make the same recommendation that Luke did.  Dictionaries
are powerful structures.  I recently wrote a Python script to parse an
English dictionary file and build Markov models out of the words
contained in the file (no, it wasn't for school, or work, or
anything...I was just really, really bored).  Rather than declaring an
int to hold the frequency information for every letter, digram, and
trigram possible (a total of 18,278 declarations), I used the letter,
digram, or trigram as a key into a dictionary.  Now I can do simple
lookups by individual letters, digrams, or trigrams and see the
frequency information without having to reference thousands of
variables, and as an added side effect, only the letters, digrams, and
trigrams that actually occur require storage.

Jonathon


Luke Paireepinart wrote:
> frank h. wrote:
>> hello, i have a string variable that  contains a name that I want to 
>> use as a variablename
>> putting aside questions of why I would like to do that - i this 
>> possible at all?
>>
>> so I want to assign a value to a variable whos name is available only 
>> as a string to me.
>> that variable does not exist yet in the local namespace.
>>
>> from: t = "myvar"
>> to: myvar = 3
>>
>> is this possible? something like setattr?
>> thanks for any insight you might have
> I think the point of dictionaries is to get this same basic 
> functionality without polluting the namespaces.
> You won't let us ask you 'why' you want to do this,
> but I'll ask you: Why don't you want to use a dictionary?
> Do you want to know if it's _Possible_ just so you'll know,
> or do you actually want to use this for something?
> If you just want to know if it's possible, I believe it is.
> But consider:
> if you don't know the variable name until runtime,
> how are you going to refer to the variable later in your code?
> It would be, insofar as I can tell, useless to do this.
>> -frank
> -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


[Tutor] executing with double click on linux

2006-10-11 Thread Jonathon Sisson
Alfonso wrote:
> Sorry for the too obvious question. I'm new to python and have no idea 
> how can I make execute a compiled .pyc with a double click in linux, 
> with gnome. Trying to double click in a .py gives allways the question 
> wether I want to execute the text file, or read it. (This behaviour can 
> be changed with gconf-editor, but as it is for security matters, I would 
> prefer to execute the .pyc with a double click). I have tried to 
> associate python to the .pyc (first time I executed it there was no 
> programm associated), but it doesn't work.
> 

I don't know how much Linux experience you have (judging by the
"double-click" concept, I'm assuming you're coming from a Windows
background or are perhaps catering to users with only a Windows
background) (correct me if I'm wrong)...so I'm going to break this down
as much as I can.

.pyc files are considered binary files by Linux.  As such, bash attempts
to execute them as binary (ELF, etc...), which obviously won't work.  If
you really need to have double-click/execute functionality, consider
writing a small shell script to execute the .pyc file for you.

For instance, let's say you have a python script "foo.py" and a compiled
python script "foo.pyc".  If you attempt to run foo.py from the shell
and you have a proper header (i.e. #!/usr/bin/python), then bash can
execute the script.  I'm assuming that GNOME has similar functionality
(I prefer Fluxbox to either GNOME or KDE), which allows your .py files
to execute directly.  .pyc, however, even with a file association, fails
to launch...on my system, I get this error:

$ ./foo.pyc
bash: ./foo.pyc: cannot execute binary file

bash recognizes the file as binary, but it fails to launch as an ELF
binary (or whatever you're set up to run).  To fix it, simply write a
shell script as such:


#!/bin/sh

python /home/me/scripts/foo.pyc



Name the script whatever you want (i.e. foo.sh) then run from the
commandline:

$ chmod 700 foo.sh

This gives the script read/write/execute permissions for the owner of
the script...if you require read/write/execute/etc...for group or all,
change 700 to whatever you need.  (i.e. 755 for rwxr-xr-x permissions)

(Alternatively you can right click on the shell script and set
permissions graphically...whichever you prefer)  Now, you should be able
to double-click the script (or preferably a shortcut to the script on
your desktop), which will launch the compiled python module for you.  If
this seems like a lot of work, then perhaps you could write a shell
script to automate the task of creating the shell script and setting
permissions each time you create a new .pyc...doh?

Hope this is a satisfactory answer...and if anyone knows something I
have overlooked, please let Alfonso and I know.

Jonathon


> Thank you for your answer.
> 
>   
> __ 
> LLama Gratis a cualquier PC del Mundo. 
> Llamadas a fijos y móviles desde 1 céntimo por minuto. 
> http://es.voice.yahoo.com
> ___
> 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] executing with double click on linux

2006-10-14 Thread Jonathon Sisson
I'm afraid I don't have enough experience with Gnome to answer your 
questions, Alfonso.  I will share what I know, though.  If you could, 
run this:

$ gnomevfs-info .pyc | grep MIME

and see what it says?  (If it gives you nothing back, then you need to 
register a MIME type for .pyc files.

http://www.gnome.org/learn/admin-guide/2.14/mimetypes-modifying.html

is the official Gnome documentation on how to accomplish that task)

You should get a MIME type of "application/x-python-bytecode".  If that 
checks out good, then my suggestion would be to place all of your python 
code in a good place (/home/user/scripts or the like) then create a 
desktop shortcut pointing to:

"python /home/user/scripts/targetScript.pyc".

If my memory serves me well, when you create a desktop shortcut you can 
tell it what command to run as well as what commandline arguements to 
pass to the program.  Split it up accordingly.

I've tested that out in idesk running on fluxbox, so I can't guarantee 
how well it will work under Gnome, but it's worth a try.  Also, if your 
script doesn't have a GUI, you'll need to point the desktop shortcut to:

"xterm -e 'python /home/user/scripts/targetScript.pyc'"

(use your favorite terminal, of course...) instead of simply "python 
/home/user/scripts/targetScript.pyc", or you'll lose the output.  (I 
checked against idesk/fluxbox while monitoring with Conky...my CPU 
shoots to 100% on a py script that I wrote that builds Markov models 
from the words in a given dictionary file...(yes, I was quite bored the 
day I wrote that...), so I know the script is indeed running even 
without a terminal to output to).

If you create the shortcut in that fashion, you *should* be able to run 
whatever python bytecode you want...

Hope this helps, and let me know how that works out for you...

Jonathon


Alfonso wrote:
> Jonathon Sisson escribió:
>> Alfonso wrote:
>>   
>>> Sorry for the too obvious question. I'm new to python and have no idea 
>>> how can I make execute a compiled .pyc with a double click in linux, 
>>> with gnome. Trying to double click in a .py gives allways the question 
>>> wether I want to execute the text file, or read it. (This behaviour can 
>>> be changed with gconf-editor, but as it is for security matters, I would 
>>> prefer to execute the .pyc with a double click). I have tried to 
>>> associate python to the .pyc (first time I executed it there was no 
>>> programm associated), but it doesn't work.
>>>
>>> 
>> I don't know how much Linux experience you have (judging by the
>> "double-click" concept, I'm assuming you're coming from a Windows
>> background or are perhaps catering to users with only a Windows
>> background) (correct me if I'm wrong)...so I'm going to break this down
>> as much as I can.
>>
>> .pyc files are considered binary files by Linux.  As such, bash attempts
>> to execute them as binary (ELF, etc...), which obviously won't work.  If
>> you really need to have double-click/execute functionality, consider
>> writing a small shell script to execute the .pyc file for you.
>>
>> For instance, let's say you have a python script "foo.py" and a compiled
>> python script "foo.pyc".  If you attempt to run foo.py from the shell
>> and you have a proper header (i.e. #!/usr/bin/python), then bash can
>> execute the script.  I'm assuming that GNOME has similar functionality
>> (I prefer Fluxbox to either GNOME or KDE), which allows your .py files
>> to execute directly.  .pyc, however, even with a file association, fails
>> to launch...on my system, I get this error:
>>
>> $ ./foo.pyc
>> bash: ./foo.pyc: cannot execute binary file
>>
>> bash recognizes the file as binary, but it fails to launch as an ELF
>> binary (or whatever you're set up to run).  To fix it, simply write a
>> shell script as such:
>>
>> 
>> #!/bin/sh
>>
>> python /home/me/scripts/foo.pyc
>>
>> 
>>
>> Name the script whatever you want (i.e. foo.sh) then run from the
>> commandline:
>>
>> $ chmod 700 foo.sh
>>
>> This gives the script read/write/execute permissions for the owner of
>> the script...if you require read/write/execute/etc...for group or all,
>> change 700 to whatever you need.  (i.e. 755 for rwxr-xr-x permissions)
>>
>> (Alternatively you can right click on the shell script and set
>> permissions graphically...whichever you prefer)  Now, you should be able
>> to double-click the script (or preferably a shortcut to the script on
>> your d

[Tutor] Zipfile and File manipulation questions.

2006-10-16 Thread Jonathon Sisson
Chris Hengge wrote:
> I chose the way I used the names because to me...
> 
> outFile = open(aFile.lower(), 'w') # Open output buffer for writing.
> = open a file with lowercase name for writing.
> it is implied that aFile is from the zip, since it is created in the 
> loop to read the zip..
> 
> outFile.write(zFile.read(insideZip)) # Write the file.
> = write what is read from inside the zip file.
> 
> I guess for declaration it isn't very clear, but thats what comments are 
> for?
> My naming was purely for my ease of mind.. I personally care less about 
> what I call it when I declare, as to how it logically flows when I go to 
> use it. I'm sure this is considered poor method, but once I declare a 
> method I tend to never need to change the declaration, just how I use 
> the info... I hope that makes sense.
> 

Even if you're the only person that EVER lays eyes on that code (and you 
inherited Perl code, so I assume someone will eventually take this code 
over) it's vital to use names that are clear and concise.  If you 
disagree, put your code away in a locked box, then re-read it after six 
months and see if it makes perfect sense.

As Kent said, this is quite a minor issue that shouldn't be paraded, but 
I have been on the receiving end of code such as:


int a;

if (a == 0)
{
/* do something interesting */
}
else
{
/* do something less interesting */
}

(Sorry for the Java-ish flair...Java happens to be on my mind at the 
moment...)

Even if I was there when the code was written, how could I know what "a" 
means a month later without digging back through to see how it's used? 
(and worse, "a" was used for conditional testing  in this specific 
example (i.e. on/off conditions), so a boolean would have done MUCH 
better).  Commenting can only help so much...the code must speak for 
itself at some point.  (Yes, I know this is an extreme example, but it 
happens all the time).

Something like this is much more readable:


boolean fileExists;

if (fileExists)
{
/* do something interesting */
}
else
{
/* do something less interesting */
}


I'm not complaining, because afterall it's up to you to write the code 
you're comfortable with (because you're not working on a team, that is), 
but a friendly suggestion on naming conventions (especially when you can 
refactor in most IDE's today) could go a long ways to helping you build 
readable code that is easier to maintain.

Jonathon


> On 10/16/06, *Kent Johnson* <[EMAIL PROTECTED] > 
> wrote:
> 
> Chris Hengge wrote:
>  > Here is my solution, completed with (I think) all your suggestions...
>  >
>  >
> #
>  > def extractZip(filePathName):
>  > """
>  > This method recieves the zip file name for decompression,
> placing the
>  > contents of the zip file appropriately.
>  > """
>  > if filePathName == "":
>  > print "No file provided...\n"
>  > else:
>  > try: # Attempt to unzip file.
>  > zFile = zipfile.ZipFile(filePathName.strip('"'), "r")
>  > for aFile in zFile.namelist(): # For every file in
> the zip.
>  > # If the file ends with a needed extension,
> extract it.
>  > for ext in ['.cap', '.hex', '.fru', '.cfg', '.sdr']:
>  > if aFile.lower().endswith(ext):
>  > insideZip = aFile # Copy of Filename.
>  > if "/" in aFile: # Split the filename if '/'.
>  >   aFile = aFile.rsplit('/', 1)[-1]
>  > elif  "\\" in aFile: # Split the filename
> if '\'.
>  >   aFile = aFile.rsplit('\\',
>  > 1)[-1]
>  > outfile = open( aFile.lower(), 'w') # Open
>  > output buffer for writing.
>  > outfile.write(zFile.read(insideZip)) #
> Write the
>  > file.
>  > outfile.close() # Close the output file
> buffer.
>  > print "Resource extraction completed successfully!\n"
>  > except IOerror, message: # If file creation fails, let
> the user
>  > know.
>  > print "File could not be written: \n"
>  > print message
>  >
>  >
> #
>  > Definatly an improvement! Thanks Kent.
> 
> Yes, that is what I meant. One minor quibble, I think I would keep
> aFile
>   as the name in the zip, since that is what it starts as, and use a new
> name for the external file name. Maybe you could use better names, for
> example zipPath and fileName. I think that would make the code a little
> clearer but it is a very minor point.
> 
> Kent
> 
> 
> 
> 

Re: [Tutor] Zipfile and File manipulation questions.

2006-10-16 Thread Jonathon Sisson
Yes, I read your code, as well as this entire thread.  All I'm saying is 
that:

#1) I'm not complaining about your naming conventions.

#2) It would be easier *on you* in the long run if you use more concise 
names.

#3) Code how you are comfortable coding...just don't expect "aFile" to 
fly in a team setting.

I'm not trying to run you down or "bare my fangs" for bad naming 
conventions, seriously, I'm not.  This list's intent is to help, and 
Kent, Luke, myself, and a whole slew of other programmers have made 
suggestions that you simply cast aside.  (Again, it is *your* decision, 
but don't expect any of us to be much help if we can't read your code 
and go "oh, that's what he's trying to do there" without serious 
effort).  None of us are getting paid to figure out what your code does, 
then formulate an answer and post it to this list.  We do that because 
we're trying to help.

I apologise if the tone of my last post was misunderstood, Chris.  I'm 
not trying to be "Mr. Enforcer" here or nothing (I'd rather think I'm 
far from capable), but don't take constructive criticism wrong.

I'm glad you got the code working.  Congrats.

Jonathon


Chris Hengge wrote:
> Have you even read my code to see if you find it cryptic? I'm starting 
> to beleive people just read the one comment on possibly using better 
> naming conventions and assumed I had picked completely irrelivent names.
> 
> On 10/16/06, *Jonathon Sisson* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> Chris Hengge wrote:
>  > I chose the way I used the names because to me...
>  >
>  > outFile = open(aFile.lower(), 'w') # Open output buffer for writing.
>  > = open a file with lowercase name for writing.
>  > it is implied that aFile is from the zip, since it is created in the
>  > loop to read the zip..
>  >
>  > outFile.write(zFile.read(insideZip)) # Write the file.
>  > = write what is read from inside the zip file.
>  >
>  > I guess for declaration it isn't very clear, but thats what
> comments are
>  > for?
>  > My naming was purely for my ease of mind.. I personally care less
> about
>  > what I call it when I declare, as to how it logically flows when
> I go to
>  > use it. I'm sure this is considered poor method, but once I declare a
>  > method I tend to never need to change the declaration, just how I use
>  > the info... I hope that makes sense.
>  >
> 
> Even if you're the only person that EVER lays eyes on that code (and
> you
> inherited Perl code, so I assume someone will eventually take this code
> over) it's vital to use names that are clear and concise.  If you
> disagree, put your code away in a locked box, then re-read it after six
> months and see if it makes perfect sense.
> 
> As Kent said, this is quite a minor issue that shouldn't be paraded, but
> I have been on the receiving end of code such as:
> 
> 
> int a;
> 
> if (a == 0)
> {
> /* do something interesting */
> }
> else
> {
> /* do something less interesting */
> }
> 
> (Sorry for the Java-ish flair...Java happens to be on my mind at the
> moment...)
> 
> Even if I was there when the code was written, how could I know what
> "a"
> means a month later without digging back through to see how it's used?
> (and worse, "a" was used for conditional testing  in this specific
> example (i.e. on/off conditions), so a boolean would have done MUCH
> better).  Commenting can only help so much...the code must speak for
> itself at some point.  (Yes, I know this is an extreme example, but it
> happens all the time).
> 
> Something like this is much more readable:
> 
> 
> boolean fileExists;
> 
> if (fileExists)
> {
> /* do something interesting */
> }
> else
> {
> /* do something less interesting */
> }
> 
> 
> I'm not complaining, because afterall it's up to you to write the code
> you're comfortable with (because you're not working on a team, that is),
> but a friendly suggestion on naming conventions (especially when you can
> refactor in most IDE's today) could go a long ways to helping you build
> readable code that is easier to maintain.
> 
> Jonathon
> 
> 
>  > On 10/16/06, *Kent Johnson* <[EMAIL PROTECTED]
> <mailto

Re: [Tutor] Mailing list question

2006-10-26 Thread Jonathon Sisson
Greetings everyone...

I use Thunderbird, too.  I've noticed that it handles threads a bit 
strange...for instance, I have pytutor set up to send me copies of my 
replies (so I can track threads better), but Thunderbird won't display 
my replies inline with the threads...

If you go to the folder you want to see threads in, then click on view, 
you can look at your thread settings.  Under "sort by" you should be 
able to set "Threaded" or "unthreaded", and under Threads (under the 
view menu) you should have it set to "all".  I know that there are 
subtle differences between Firefox for Windows and Firefox for *nix, but 
I don't know about Thunderbird.  If you're using Windows, there might be 
slight differences between what you see what I see in the menus.

I don't know if that helps at all, but that's how I have Thunderbird set 
up when it comes to threads.

Jonathon


Alan Gauld wrote:
> "Jorge Azedo" <[EMAIL PROTECTED]> wrote 
>> How do I reply to a specific thread in the mailing list? 
> 
> Just hit Reply All.
> There should be a command or button in your mail tool 
> to do that, even if you use web mail.
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] move forward in arbitrary direction

2006-10-28 Thread Jonathon Sisson
The "something" you're stuck on is the angle the triangle has rotated, 
measured in radians.  If the concept of radians is not familiar, then 
here's a quick review:

There are 2*pi radians in a complete circle (about 6.28)
There are 360 degrees in a complete circle
1 radian is approximately 57 degrees

Going by radians, 0.0*pi is pointing to the right, 0.5*pi is pointing 
down, 1.0*pi is pointing to the left, and 1.5*pi is pointing straight up.

Keep in mind that python has a math function radians(x), which converts 
"x" degrees to radians.  If you use that, you can use degrees instead 
and convert on the fly.  (i.e. something to the effect of: 
math.cos(math.radians(degrees)) would give you the change in vector[0]).
If you would rather use radians, keep in mind that the python math 
module also has the pi constant, which is pretty self explanatory...

Hope that helps you...

Jonathon



Michael Shulman wrote:
> Hello, I have what should be a basic math question, but I keep messing 
> it up.
> 
> How do I code an equation so that when I have an object facing an 
> arbitrary vector, pressing a key will make it move forwards in that 
> direction?
> (I understand all the key-based setup, it's just the equation for moving 
> in the arbitrary vector direction that's got me stuck)
> 
> right now i can make something move up and down, or left and right, but 
> if I want to rotate a triangle, then move it so that the 'tip' always 
> points in the direction it's going to move, I get stuck.
> 
> the thing I have which doesn't work is something like
> _
> vector = [0 0 0]
> 
> def specialKey(key,x,y):
> if key  == 'up':
>vector[0] = vector[0] + 1
> ___
> which I assume should be more like
> 
> vector = [0 0 0]
> 
> def specialKey(key,x,y):
> if key  == 'up':
>vector[0] =  vector[0] * math.cos(something???)+ 1
>vector[2] =  vector[2] * math.sin(something??)+1
> --
> Any help would be greatly appreciated!
> 
> ty, Mike
> ___
> 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] I am terribly confused about "generators" and "iterators".. Help me

2006-10-28 Thread Jonathon Sisson
My understanding is that an iterator is basically a facade` pattern.  If 
you aren't familiar with patterns, a facade` pattern basically makes 
something really easy to use or convenient.  Yes, you can "do it by 
hand", and many times that is indeed the preferred method, but sometimes 
it's easier to use an iterator...particularly if it isn't a special 
case.  Nothing in the manual says you HAVE to use iterators, but they 
*can* make life easier.

Jonathon

Asrarahmed Kadri wrote:
>  
>  
> Hi Folks,
>  
> What are generators and iterators...??And why are they are needed..??
>  
> I can do my stuff with a 'for' or a 'while' loop.. so why do I need an 
> ITERATOR..?
>  
> And what is a generator ..? I did try to read about these two things on 
> the web, but still I AM CONFUSED.
>  
> To be honest, I am used to the nice and lucid style of the wonderful 
> people on this forum.. :)-
>  
> Regards,
> Asrarahmed Kadri
> 
> 
> -- 
> To HIM you shall return.
> 
> 
> 
> 
> ___
> 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] move forward in arbitrary direction

2006-10-28 Thread Jonathon Sisson
Hrmmm...I do believe you are right, Luke.  My bad...it's been a bit 
since I actually used this stuff (about 12 years ago in college...heh). 
  And yes, it would matter, unless you swapped the key functionality 
around...but let's keep it simple, yes?

Good thing I'm not programming this project...haha.

Doh?
Jonathon


Luke Paireepinart wrote:
> 
> 
> Going by radians, 0.0*pi is pointing to the right, 0.5*pi is pointing
> down, 1.0*pi is pointing to the left, and 1.5*pi is pointing
> straight up.
> 
> 
> uh, wouldn't pi/2 be pointing up?
> Don't you set 0 radians to be the positive-x axis and then go 
> counter-clockwise?
> Or does it not matter?
> It seems like it would.
> Thanks,
> -Luke
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question

2006-11-03 Thread Jonathon Sisson
Hi Doug,

I'm not a Python guru, but shouldn't you be putting the output of 
file.split('\n') into a list, and not back into a string (for clarity's 
sake?).

Also, if you have two trailing newlines on the file, your final string 
will be '', so you should be doing clean1.append(i[26:40]) in your for 
loop, right?

Let me know if that helps...

Jonathon


Doug Potter wrote:
> I don't get  the output I would expect from the following.
> The variable clean1 gives me an empty string.  But if i change the for 
> loop to print i[26:40] I get all the info.
> what do I need to do to capture all the data to clean1? 
> 
> Thanks.
> 
>  >>> a = open('arp.txt')
>  >>> file = a.read()
>  >>> file = file.split('\n')
>  >>> a.close()
>  >>> b = open('arplist.txt','w')
>  >>> clean1 = []
>  >>>
>  >>> for i in file:
> ... clean1 = i[26:40]
> ...
>  >>> clean1
> ''
> 
> ___
> 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] Print Screen

2006-11-04 Thread Jonathon Sisson
Chris,

I don't know if this has been mentioned yet, but this site might be useful:

http://bdash.net.nz/blog/2003/12/24/python-vnc-client/

The code base has (last I heard) fallen stagnant, but it may very well 
be worth a look as a starting point for your VNC project idea.

Jonathon


Chris Hengge wrote:
> Wow.. I have visions of writing a little wanna-be VNC client/server now 
> using the ImageGrab.grab() =D
> This ImageGrab trick does exactly what I wanted. Thanks for the tip!
> 
> Actually, I want to write a little package for the learning experience 
> sometime over the holidays (plus I use VNC fairly often), but I can't 
> find any direction, or any already made packages for python for the VNC 
> protocol (no libs?).
> 
> On 11/2/06, *Luke Paireepinart* <[EMAIL PROTECTED] 
> > wrote:
> 
> 
>  >> Anyone know of a way to capture special keys like "Print Screen"?
>  >> I have a small script to grab all they keycodes, but it doesn't
> seem to
>  >> catch several keys on the keyboard. I've got a utility that I'd
> like to
>  >> be able to automagically get a screenshot when something goes
> wrong so I
>  >> dont have to hope the user can re-create the error. Universal
> support
>  >> would be best, but WinXP is the main OS
>  >>
>  >>
>  >
>  > I'm not exactly sure what you want here :-) but if you want to
> capture
>  > when the 'Print Screen' key (or any other key) has actually been
>  > pressed, try pyHook. Note: pyHook only works on Windows!
>  >
> Also note that if you want all of the keypresses, but you _don't_ care
> about the application with focus
> receiving the input, you can do a complete key grab using TKInter or
> Pygame, and probably the other GUI packages too.
> But, like I said, if you were, for example, typing an e-mail and you
> started a script that did a complete grab like this, you'd no longer be
> able to type
> into the e-mail window.  Using pyHook, your program could see all the
> keypresses, but they'd also still be sent to the e-mail program.
> Actually, I've never tried it, but I'm pretty sure that's how the GUI
> packages' key capturing works.
> You may be asking 'well, it sounds like pyHook does a better job of
> this
> anyway!'
> Yeah, you're right.
> However, as Alan exclaimed, pyHook works only on Windows!
> So the solution I offered would be more portable.
> Hope that helps,
> -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] Amazing power of Regular Expressions...

2006-11-04 Thread Jonathon Sisson
Asrarahmed Kadri wrote:
 > tries to supply negative values, then match will return None.
 > So no hassle of using all those Ifs  and Elifs
 > I think REGULAR Expressions can be quite powerful...

Indeed...Regular expressions were discovered etched into the blade of a 
sword that had been planted into a rock somewhere in ancient 
England...(yes, I'm kidding...but discovering RE's can make you feel 
that way...)

Regular Expressions can be cryptic at first, but once you get the hang 
of them they're addicting... As Alan Gauld stated in another thread (I'm 
pretty sure it was Alan): You'll get to the point that you want to use 
(regular expressions) all the time, even if they aren't the right tool 
for the job.  If something like a string function or a list slice can 
handle the job, don't go overkill on it.

I speak from experience...listen to Alan's advice.  I have used RE's 
where they weren't the right tool, and the deeper I got into the code 
the more I was made aware that RE's were a bad choice.  It's tough to 
dump a week or two's worth of work because of one bad decision...most of 
the time the tendency is to force the bad decision, and this leads to 
bad code...

To summarize:

Regular Expressions:  learn them, love them, use them...but put the 
sword down if a pen can handle the job better.

Jonathon



> 
> Hi Folks,
>  
>  
> I dont know much about Regular Expressions. But I just want to share my 
> ideas.
>  
> I was trying to implement error checking code on the date argument:
>  
> I did this:  
>  
> import re
> # the user should enter date in the format: dd/mm/
> p = re.compile('\d\d/\d\d/\d\d\d\d')
>  
> m = p.match(date)
>  
> the function match will return an object of type SRE_Match only if the 
> user has supplied the string in the form of dd/mm/. If the user 


>  
> Regards,
> Asrarahmed
> -- 
> To HIM you shall return.
> 
> 
> 
> 
> ___
> 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] shebang problem

2006-11-04 Thread Jonathon Sisson
Brian,

It's not a permissions issue...

(from the original e-mail...see below)
 >> [EMAIL PROTECTED]:~/test$ ls -la shebangtest.py
 >> -rwxr-xr-- 1 brian brian 68 2006-11-04 02:29 shebangtest.py

This is clearly executable by brian, and clearly being executed by 
brian.  The shebang line is correct (#!/usr/bin/python).

The problem is *how* you are executing the file.  If you simply type in 
the filename, your shell looks on your PATH to find the file.  Unless 
~/test is on PATH, you'll get a "command not found" error.

Instead type in:

./shebangtest.py

and see if that works.  "./" tells the shell to look in your current 
working directory for the file.

Let me know if that solved the problem...

Jonathon


Carlos Hanson wrote:
> On Sat, November 4, 2006 4:11 pm, Brian van den Broek wrote:
>> Hi all,
>>
>> I'm still getting comfortable with Linux and this might be an OS
>> rather than a python problem.
>>
>> I am trying to make a script directly executable. I've reviewed the
>> 2nd ed of the Nutshell, and I cannot work out what I'm doing wrong.
>> I'm running ubunutu 6.10 (edgy eft). Here's a copy past of my command
>> line:
>>
>> [EMAIL PROTECTED]:~/test$ which python
>> /usr/bin/python
>> [EMAIL PROTECTED]:~/test$ ls -la shebangtest.py
>> -rwxr-xr-- 1 brian brian 68 2006-11-04 02:29 shebangtest.py
>> [EMAIL PROTECTED]:~/test$ cat shebangtest.py
>> #!/usr/bin/python
>>
>> if __name__ == '__main__':
>>
>>  print "It works"
>> [EMAIL PROTECTED]:~/test$ shebangtest
>> bash: shebangtest: command not found
>> [EMAIL PROTECTED]:~/test$ shebangtest.py
>> bash: shebangtest.py: command not found
>>
>> I've also tried:
>>
>> #!/usr/bin python
>>
>> as my shebang line.
>>
>> I've been unable to get this to work. Clearly, there is something I've
>> misunderstood. (`#!' is not an easy thing to google for :-)
>>
>> Best,
>>
>> Brian vdB
>>
> 
> Your answer lies in the file permission.  The file needs to be
> executable.  If you look at the man pages for chmod, you will find
> your answer.
> 
> The shebang line tells the shell what to use to run the script.  For
> example, if the file is not executable, you would execute it as
> follows:
> 
> $ python shebangtest.py
> 
> As you found with `which python`, python is in /usr/bin, so executing
> the script is actually
> 
> $ /usr/bin/python shebangtest.py
> 
> Therefore, the shebang line needs to be as follows:
> 
> #! /usr/bin/python
> 
> Then once the script has execute permissions (man chmod), it will run
> as expected.
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-04 Thread Jonathon Sisson
Ahh, sorry, sorry.  I haven't been able to locate the thread that I read 
that summarized passage from, so I can't say who exactly said all of that...

Nice quote on C/C++...made me laugh.

Jonathon

Alan Gauld wrote:
> "Jonathon Sisson" <[EMAIL PROTECTED]> wrote
> 
>> of them they're addicting... As Alan Gauld stated in another thread 
>> (I'm
>> pretty sure it was Alan): You'll get to the point that you want to 
>> use
>> (regular expressions) all the time, even if they aren't the right 
>> tool
> 
> Nope, it wasn't me, maybe Danny.
> 
> But I sure agree with it. The problem with Regex is that they can
> be just a bit too powerful. To cite another programming proverb,
> this time by Bjarne Stroustrup I think:
> 
> "C makes it easy to shoot yourself in the foot;
> C++ makes it  harder, but when you do,
> it blows away your whole leg."
> 
> Regex can be like that too.
> 
>> Regular Expressions:  learn them, love them, use them...but put the
>> sword down if a pen can handle the job better.
> 
> A great summary.
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] GUI with Designer

2006-11-05 Thread Jonathon Sisson
Wow...

SPE is in the Gentoo repository as well.  I've been looking for 
something to replace Eric, so thanks for the tip, Chris!  I'll check it out.

Jonathon


Chris Hengge wrote:
> Well, I use SPE which comes with wxGlade and XRC. For the small amount 
> of gui I've done with python I think SPE offers the best IDE coder 
> experience (coming from a VS world). The tools make sense to me.
> 
> wxGlade is a GUI designer written in Python with the popular GUI toolkit 
> wxPython , that helps you create 
> wxWidgets/wxPython user interfaces. At the moment it can generate 
> Python, C++, Perl and XRC (wxWidgets' XML resources) code.
> 
> XRC(wxWidgets' XML resources) is nice because it allows you to abstract 
> your interface design (think of any program that uses XML to format skins).
> 
> Overall, I think everyone using python should give SPE a try, even 
> without gui programming its a great tool for writing code. It's free, 
> and written in python using wxPython.. Stani (the Dev) is a great person 
> for helping out with questions on using his package, he puts out regular 
> updates and fixes. He's got some help from a few other people so its 
> packaged in .exe, .rpm and standalone .zip formats. It's also on the 
> standard repo's for Ubuntu.
> 
> If you like it, be kind and toss the guy a few bucks for his efforts. If 
> you do, you will get your name mentioned on the SPE news page and get a 
> nice copy of his user manual (pdf).
> 
> If you want to know more about SPE, check out:
> http://www.serpia.org/spe
> or video demonstations at:
> http://showmedo.com/videos/series?name=PythonDevelopmentWithSPE 
> 
> 
> On 11/3/06, *Dick Moores* <[EMAIL PROTECTED] > 
> wrote:
> 
> At 02:10 PM 11/3/2006, Chris Hengge wrote:
>> I vouch for the SPE with wxGlade and XRC! (packaged together with IDE)
> 
> I'd be very interested in hearing why you suggest that combination.
> 
> Dick Moores
> 
> 
>> On 11/3/06, *Carlos Daniel Ruvalcaba Valenzuela* <
>> [EMAIL PROTECTED] > wrote:
>>
>> wxPython is good for cross-platform stuff and has a few gui
>> designers
>> (Boa Constructor and others comes to mind), I don't know much
>> about
>> PyQT state in this, but PyGtk + Glade (Gui Designer) is a very
>> good
>> combo.
>>
>> Is about choise, I suggest you to do some simple tests with
>> everything
>> until you find something to be confortable with.
>>
>> * PyGtk + Glade
>> * Boa Contructor
>> * SPE + wxPython
>>
>> On 11/3/06, Todd Dahl <[EMAIL PROTECTED]
>> > wrote:
>> > I am wanting to get into some GUI coding with Python and have
>> heard about
>> > PyQT and wxPython. Now I am definately not looking for some
>> type of holy war
>> > but can anyone give me a good reason to pick one over the other.
>> >
>> > Also I would like to have a designer with it or a seperate
>> designer that
>> > could be used with either. I plan on coding in Windows XP.
>> >
>> > Thanks,
>> >
>> > -Todd
>> >
>> > ___
>> > 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
> 
> 
> 
> 
> 
> ___
> 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] Amazing power of Regular Expressions...

2006-11-06 Thread Jonathon Sisson
Just out of curiousity (since I really can't say myself), does the code 
below import re each time it loops?  I ran the same commands and saw 
quite similar results (0.176 usec per loop for the first test and 0.993 
usec per loop for the second test), and I was just curious if that 
import (and the re.compile, for that matter) happen with each loop?

Jonathon

John Fouhy wrote:
> On 07/11/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
>> If anyone really cares which Python implementation is faster, the timeit
>> module is your friend. Assertions like "would probably be faster" or
>> "it's also quicker" don't hold much weight. In Python, if you want to
>> know what is faster, you must test.
> 
> Hmm, what exactly is the contentious code?
> 
> Morpork:~ repton$ python -m timeit -s
> 's="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"'
> '"J" in s'
> 100 loops, best of 3: 0.295 usec per loop
> Morpork:~ repton$ python -m timeit -s 'import re' -s 'r =
> re.compile("[0-9A-Za-z_.-]")' 'r.match("J")'
> 100 loops, best of 3: 1.16 usec per loop
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-06 Thread Jonathon Sisson
John,

Thanks...I was a bit deep in a script trying to figure out why I kept 
getting global key errors (trying to make sure that re.compile and 
import re weren't run but once...doh?) when you responded.

I guess that settles it, then...for this particular instance, '"J" in s' 
is indeed faster than 'r.match("J")'...

Jonathon


John Fouhy wrote:
> On 07/11/06, Jonathon Sisson <[EMAIL PROTECTED]> wrote:
>> Just out of curiousity (since I really can't say myself), does the code
>> below import re each time it loops?  I ran the same commands and saw
>> quite similar results (0.176 usec per loop for the first test and 0.993
>> usec per loop for the second test), and I was just curious if that
>> import (and the re.compile, for that matter) happen with each loop?
> 
> Nope.
> 
> Here's the command again:
> 
> python -m timeit -s 'import re' -s 'r = re.compile("[0-9A-Za-z_.-]")'
> 'r.match("J")'
> 
> -s means "startup code".  So, 'import re' and 're.compile(...)' happen
> only once, before the main test starts.
> 
> You can read help on timeit by typing 'import timeit; help(timeit)' in
> the python console.
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Data hiding in Python.

2006-12-19 Thread Jonathon Sisson

> My vote is, no, not worth the trouble. It's Java / C++ / static-typing / 
> put-the-client-in-a-straightjacket-so-they-don't-touch-anything thinking.
> 

Heh...and don't forget the king-pin of them all, C#.  Between private, 
public, protected, internal, and protected internal I lose track of what 
I was originally doing and end up contemplating the meaning of "what if 
another programmer wants to use this creation of mine" instead of doing 
what I set out to do...

I'm with Kent on this one...definitely not worth the trouble to 
bastardize Python like that...

As a side note, does anyone have a good argument for access level 
controls like C#?  I personally think it's a waste of time (much like 
C#/ASP.NET...my apologies to any .NET fans out there...), and honestly 
the arguable margin of security that access modifiers provide is 
outweighed by the cons, in my opinion.  (And usually what programmers 
end up doing is creating "service methods" that allow access anyways, so 
the margin of "security" is lost).  Thoughts?

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


Re: [Tutor] Data hiding in Python.

2006-12-19 Thread Jonathon Sisson
Alan Gauld wrote:
> but also enforces that intent. This is espectially important
> during the early development of libraries where the internal
> representation is constantly evolving.

Yeah, I would have to agree with you there.  I hadn't considered that 
angle...

> But multiple languages compiling to a common runtime
> all with a single class library is powerful medicine...

I would argue the only real "innovation" provided by .NET is just that: 
the ability to produce and consume project components from different 
languages.

I have to say I'd still prefer Java development over .NET, but that's 
probably more personal issues with Microsoft than language implementation.

I recently used Python for a relatively large project for a Linux 
scripting class (the professor was kind enough to allow any relatively 
common scripting language (i.e. available on our Linux server...heh)) 
and I have to admit, I'm much more productive with Python than with 
virtually any language I've used before. (No, I haven't tried Ruby yet, 
but I hear it's just as addicting).  Access modifiers or not, you can't 
really argue with development productivity like that...or the grade that 
I got on that project. =)  And, it was actually kind of fun listening to 
some other students gripe about Perl...haha.

Anyhow, thanks for the additional info, Alan!

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


Re: [Tutor] Project Review

2006-12-21 Thread Jonathon Sisson
Christopher Arndt wrote:
> P.S. This is basically just rephrasing what has been already said by others 
> and
> better: http://www.catb.org/~esr/faqs/smart-questions.html


Seriously, that is an excellent guide.  Eric S. Raymond writes some high 
quality stuff.  Anyone new to posting on this list (or any other, for 
that matter) should read that.  I highly recommend it and thanks Chris 
for posting that link.

And check out some of Eric's other guides and essays as well.  A 
particular favorite of mine (especially if you are interested in open 
source software and the development model utilized by most of the open 
source community) is http://www.catb.org/~esr/writings/cathedral-bazaar/

Great post, Chris.  Thanks!

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