Re: [Tutor] Installing twisted

2014-11-27 Thread Scott W Dunning
Hey guys I was hoping someone could tell me how to opted out of this list?  I 
have it going to two email addresses for some reason and I unsubscribed but 
nothing happened.  Any help is greatly appreciated!  

Thanks,

Scott 


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


Re: [Tutor] Final review

2014-05-07 Thread Scott W Dunning

On May 5, 2014, at 10:13 PM, meenu ravi  wrote:

> Likewise, the index of d, which is the last word in the word "Hello world" is 
> 10.
> 
> So, the maximum index you can access in the word "Hello world" is 10. But 
> when you try to give the command,
> 
> >>> greeting [len(greeting)]
> 
> It is trying to access the character at the position "11", where the string 
> "Hello world" doesn't contain any value in the index "11" and the maximum 
> index is 10. So it throws the following error.

I think this is where I am getting confused.  I guess I don’t understand 
why/how it’s trying to access the character at the index 11?
>  
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> IndexError: string index out of range
> 
> So always the maximum index will be length - 1. So if you want to access the 
> last character of the string "Hello world", give the command:
> 
> >>> greeting[len(greeting)-1]
> 
> 'd'
> 
> Hope this helps

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


Re: [Tutor] Final review

2014-05-05 Thread Scott W Dunning

On May 1, 2014, at 5:30 AM, Steven D'Aprano  wrote:

Awesome, thanks everyone!  I understand lists a lot better now.  

I have another question.  I don’t understand why below would give an error?

>>>  greeting = 'Hello World’
>>>  greeting [len(greeting)]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Final review

2014-05-01 Thread Scott W Dunning
Hello, I am new to python and have a final review coming up and was hoping you 
could help me answer a few questions I came across while studying.


So, I get a little confused about lists sometimes.  This one is a little hard 
to make heads or tails of.  I get confused about how to tell how many lists are 
within one list like the one below.   How many lists are located inside alist 
is it 1 or 2, 3??  Also, do spaces count as an index in lists?  

>>> alist = [3, 67, "cat”, [56, 57, “dog”], [], 3.14, False]
>>> print alist[4:]
[[], 3.14, False]


The ouput for below is 2 when it seems like there should be 3 lists located 
inside x.  Is it [10,20] that is not consider inside of x?Any tips on how 
to tell how to spot them more clearly?  

x = ['a', [2.0, 5, [10, 20]]]
print len(x)



I have a few more questions too but I figured I send this email for now while 
compile my other questions you guys can hopefully help to shed light on. 

Thanks for any help!!

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


Re: [Tutor] exercise (while loop)

2014-03-31 Thread Scott W Dunning

On Mar 31, 2014, at 7:10 PM, Danny Yoo  wrote:
Thanks for the info Danny!  I’ll try that and I should be able to figure it out 
with your help!  

The book I was referring to is greentreepress.

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


[Tutor] exercise (while loop)

2014-03-31 Thread Scott W Dunning
I’m working on a few exercises and I’m a little stuck on this one.  

This is what the book has but it just gives me an endless loop.

def square_root(a, eps=1e-6):
while True:
print x
y = (x + a/x) / 2
if abs(y-x) < epsilon:
break

round(square_root(9))

I tweaked it to what I thought was correct but when I test it I get nothing 
back.

def square_root(a, eps=1e-6):
   x = a/2.0
   while True:
   y = (x + a/x)/2.0
   if abs(x - y) < eps:
   return y
   x = y

round(square_root(9))

The way I tweaked it seems to work, I’m getting the correct answer on the 
calculator but the interpreter is not returning anything when I check in python.

The books way is just print whatever I use for x, so I don’t understand that at 
all.


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


[Tutor] while loop

2014-03-28 Thread Scott W Dunning
Hello, I’m working on some practice exercises from my homework and I’m having 
some issues figuring out what is wanted.  

We’re working with the while loop and this is what the question states;

Write a function print_n that prints a string n times using iteration.

"""Print the string `s`, `n` times. 


This is also in the exercises and I’m not sure what it means and why it’s there.

assert isinstance(s, str)
assert isinstance(n, int)


Any help is greatly appreciated!

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


Re: [Tutor] while loop

2014-03-28 Thread Scott W Dunning

On Mar 28, 2014, at 9:54 PM, Scott W Dunning  wrote:

> Hello, I’m working on some practice exercises from my homework and I’m having 
> some issues figuring out what is wanted.  
> 
> We’re working with the while loop and this is what the question states;
> 
> Write a function print_n that prints a string n times using iteration.
> 
>   """Print the string `s`, `n` times. 
> 
> 
> This is also in the exercises and I’m not sure what it means and why it’s 
> there.
> 
> assert isinstance(s, str)
> assert isinstance(n, int)
> 
> 
> Any help is greatly appreciated!
> 
> Scott

This is what I have so far but I’m not really sure it’s what the excersise is 
asking for?

n = 5
def print_n(s, n):
   while n > 0:
   print s * n

print_n("hello", 10)


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


[Tutor] Project suggestions

2014-03-12 Thread Scott W Dunning
Hey Everyone,

I just got through doing a Guess-the-number script and was looking for 
something else to practice on.  Do any of you have any suggestions on some 
things I could work on?  Keep in mind I am not only extremely new to python I 
am new to programming.  Thanks for any suggestions!!!

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


Re: [Tutor] Help with Guess the number script

2014-03-11 Thread Scott W Dunning

On Mar 11, 2014, at 7:50 PM, William Ray Wing  wrote:
> 
> Simple.  In Mail Preferences -> Composing -> Message Format -> Plain Text  
> (Your setting is probably currently Rich Text.)
> 
Got it, hopefully that helps.

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


Re: [Tutor] Help with Guess the number script

2014-03-11 Thread Scott W Dunning

On Mar 11, 2014, at 1:49 AM, Alan Gauld  wrote:
> 
> Not from the tutor list though. It only has a few
> mails normally - less than 50 most days.
> 
Actually now that you say that most of the emails are coming through the reg 
python-lists, not the tutor section.  I guess I should just unsubscribe from 
python-lists because my questions are going through the tutor section for 
awhile.  
>> I’m not trying to be rude I’m just wondering,
> 
> What tends to irritate folks is the HTML content
> which different readers display differently.
> Especially the indentation which often gets lost.
> You need to explicitly go into your mail tool
> options and select "plain text" rather than
> "rich text" or "HTML" which will likely be the
> default.
> 
> You can often tell if you don't have plain text
> because you will have options to change font,
> size, colour etc. You can't do any of that with
> plain text. But modern mail tools often make it
> very difficult to set plain text, especially
> web based ones.
> 
Yeah, I had no idea that my messages were coming through in HTML, nor what it 
looked like until someone sent me a section showing me what it looked like, I 
can see how that would be frustrating.  

I’m using the mail app on my macbook pro, any suggestions on how to stop it 
from going out as html?  Do I need to change the font?  Also, I think last time 
I sent a section of my code I copy and pasted it from my script, could that be 
the problem?

Thanks again!

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


Re: [Tutor] Help with Guess the number script

2014-03-11 Thread Scott W Dunning

On Mar 10, 2014, at 11:18 PM, Dave Angel  wrote:

Where are you guys using the forum?  Through google?  I was using that at first 
but someone complained about something that google does and told me to get it 
through my email.  That’s what I’m doing now and I get bombarded with about 500 
emails a day but I’m still doing something wrong?  I’d rather go though a site 
to view the forum anyways, it seems way easier then having to sort through 
hundreds of emails.  I’m not trying to be rude I’m just wondering, I don’t want 
to be irritating people if by doing something wrong.  Thanks again for all of 
your help!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Guess the number script

2014-03-11 Thread Scott W Dunning

On Mar 10, 2014, at 11:18 PM, Dave Angel  wrote:

> Scott W Dunning  Wrote in message:
>> 
> 
> Would you please stop posting in html?
I don’t know what you mean?  I just use the text for my email provider.   It’s 
not html?  I types up the code I had in the script.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Guess the number script

2014-03-10 Thread Scott W Dunning

On Mar 8, 2014, at 11:50 AM, Scott dunning  wrote:
>>> 
>>> And now that you have the right set of tests you can
>>> half the number of lines by combining your if
>>> conditions again, like you had in the original
>>> post. ie. Bring your hot/cold/warm tests together.
I’m having a hard time doing that because the guess can be either too low or 
too high but it is always either cold, warm, or on fire.  I can’t figure out 
how to make it work with out splitting the cold, warm and on fire under two 
branches, one too low and one too high.  Any suggestions?

Thanks!


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


Re: [Tutor] Python implementations (was: Help with Guess the number script)

2014-03-10 Thread Scott W Dunning

On Mar 10, 2014, at 8:52 PM, Ben Finney  wrote:
> 
> What does the Python interactive prompt display when you first launch an
> interactive Python shell?

Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python implementations (was: Help with Guess the number script)

2014-03-10 Thread Scott W Dunning

On Mar 10, 2014, at 8:52 PM, Ben Finney  wrote:
> 
> What does the Python interactive prompt display when you first launch an
> interactive Python shell?

Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Guess the number script

2014-03-10 Thread Scott W Dunning
>> On Mar 8, 2014, at 3:57 AM, spir  wrote:
>>> 
>>> Well done.
>>> And now that you have the right set of tests you can
>>> half the number of lines by combining your if
>>> conditions again, like you had in the original
>>> post. ie. Bring your hot/cold/warm tests together.

So below is what I finally came up with that works.  I’m trying to condense it 
to half the number of lines like Denis suggested.  I was hoping to clarify a 
couple things if you guys don’t mind….

I wanna make sure I understand how this code is working.  So, from what I 
gather it first checks to see if the ‘guess’ is out of range and if that is 
false it continues to the next ‘if’ statement checking wether it’s too low.  
Now this is where I’m not 100% sure if the too low ‘if’ statement is false does 
it skip everything that is nested below it (you are cold, warm, on fire) and go 
to the ‘if statement checking if it’s too high?   And now say the too low ‘if’ 
statement is true, because it’s an ‘if’ the code does not stop it continues but 
when it gets to the elif the code stops?  
def print_hints(secret, guess):
if guess < 1 or guess > 100:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
if guess < secret - 10:
print "You are cold!"
print
print "Sorry please try again."
print
print
elif guess < secret - 5:
print "You are warmer!"
print
print "Sorry please try again."
print
print
else:
print "You're on fire!!"
print
print "Sorry please try again."
print
print
if guess > secret:
print
print "Too high!"
if guess > secret + 10:
print "You are cold!"
print
print "Sorry please try again."
print
print
elif guess > secret + 5:
print "You are warmer!"
print
print "Sorry please try again."
print
print
else:
print "You're on fire!!"
print
print "Sorry please try again."
print
print

This is what I have right now, obviously it’s not working.  I’ve been playing 
around with it but I’m just not seeing where I’m going wrong.  Any suggestions 
are greatly appreciated!

def print_hints(secret, guess):
if guess < 1 or guess > 100:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
if guess > secret:
print
print "Too high!"
if guess < secret - 10 or guess > secret - 10:
print "You are cold!"
print
print "Sorry please try again."
print
print
elif guess < secret - 5 or guess > secret - 5:
print "You are warmer!"
print
print "Sorry please try again."
print
print
else:
print "You're on fire!!"
print
print "Sorry please try again."
print
print
   

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


Re: [Tutor] Help with Guess the number script

2014-03-10 Thread Scott W Dunning

On Mar 10, 2014, at 4:15 AM, eryksun  wrote:
> 
> Different strokes for different folks. I like to tinker with and
> disassemble things as I'm learning about them. I would have been
> ecstatic about open source as a kid. I learn simultaneously from the
> top down and bottom up -- outside to inside and inside to outside. I
> need an abstract overview (a map) combined with a concrete
> realization. Tell me and show me -- and let me tinker and experiment.
> If learning isn't fun, I'm not learning.

I agree I learn the same way.  I just didn’t understand what you were saying.  
What exactly is Cpython?  Is it different from the python I’m using?  Also, 
what did you mean by;
>> The disjunctive expression is actually
>> implemented more efficiently by CPython's compiler, which you can
>> verify using the dis module to disassemble the bytecode.


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


Re: [Tutor] Help with Guess the number script

2014-03-10 Thread Scott W Dunning

On Mar 8, 2014, at 7:35 AM, Mark Lawrence  wrote:
> 
> I have no interest in the efficiency, only what is easiest for me to read, 
> which in this case is the chained comparison.  As a rule of thumb I'd also 
> prefer it to be logically correct :)
> 
What exactly is ment by a chained comparison?  Wouldn’t what I wrote be chained?

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


Re: [Tutor] Help with Guess the number script

2014-03-10 Thread Scott W Dunning

On Mar 8, 2014, at 7:29 AM, eryksun  wrote:
> i.e.
> 
>guess < 1 or guess > 100
> 
> becomes
> 
>not not (guess < 1 or guess > 100)
Why a not not?  Wouldn’t that just be saying do this because the second not is 
undoing the first? 
> 
> distribute over the disjunction
> 
>not (not (guess < 1) and not (guess > 100))
> 
> logically negate the comparisons
> 
>not (1 <= guess and guess <= 100)
> 
> finally, write the conjoined comparisons as a chained comparison:
> 
>not (1 <= guess <= 100)
> 
> i.e., guess isn't in the closed interval [1, 100].
> 
> Anyway, you needn't go out of your way to rewrite the expression using
> a chained comparison. The disjunctive expression is actually
> implemented more efficiently by CPython's compiler, which you can
> verify using the dis module to disassemble the bytecode.
I’m not sure what you’re talking about in the above paragraph.  

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


Re: [Tutor] Help with Guess the number script

2014-03-08 Thread Scott W Dunning

On Mar 7, 2014, at 11:02 AM, Alan Gauld  wrote:

GOT IT!!  Finally!  Thanks for all of your help!!

This is what I got, not sure if it’s correct but it’s working!

def print_hints(secret, guess):
if guess < 1 or guess > 100:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
if guess < secret - 10:
print "You are cold!"
print
print "Please play again!"
elif guess < secret - 5:
print "You are warmer!"
print
print "Please play again"
else:
print "You're on fire!!"
print
print "Please play again"
if guess > secret:
print
print "Too high!"
if guess > secret + 10:
print "You are cold!"
print
print "Please play again!"
elif guess > secret + 5:
print "You are warmer!"
print
print "Please play again"
else:
print "You're on fire!!"
print
print "Please play again"

   

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


[Tutor] Help with Guess the number script

2014-03-07 Thread Scott W Dunning
I am trying to write a script for class for a game called guess the number.  
I’m almost done but, I’m having a hard time getting the hints to print 
correctly.  I’ve tried ‘if’’ ‘elif’ nested, it seems like everything….I’m 
posting my code for the hints below, any help is greatly appreciated!  

def print_hints(secret, guess):
if guess < 1 or guess > 101:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
elif guess < (secret - 10) or guess > (secret - 10):
print "You are cold!"
print
print "Please play again!"
elif guess < (secret - 5) or guess > (secret - 5):
print "You are warmer!"
print
else:
print "You're on fire!!"

if guess > secret:
print
print "Too high!"
print
elif guess < (secret - 10) or guess > (secret - 10):
print "You are cold!"
print
elif guess < (secret - 5)or guess > (secret - 5):
print "You are warmer!"
print
print "Please play again!"
else:
print "You're on fire!!"


Thanks again!!

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


Re: [Tutor] Help with "Guess the number" script

2014-03-04 Thread Scott W Dunning

On Mar 3, 2014, at 3:29 AM, spir  wrote:

I have another question in regard to this guess the number script I’m working 
on.  I’m banging my head over why this isn’t working….

def print_hints(secret, guess):
if guess < 1 or guess > 101:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
if guess < (secret - 10) or guess > (secret - 10):
print "You are cold!"
print
print "Please play again!"
if guess > secret:
print
print "Too high!"
print
print "Please play again!"
if guess < (secret - 5) or guess > (secret - 5):
print "You are cold!"
print
print "Please play again!”

I keep getting a syntax error about the indenting for this elif being wrong?  
Any suggestions?

elif:
print "You're on fire!!"


Thanks again!!

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


Re: [Tutor] Help with "Guess the number" script

2014-03-04 Thread Scott W Dunning

On Mar 3, 2014, at 3:27 AM, spir  wrote:
> 
> There are 2 user guesses here, and only 1 variable, thus 1 name. The name 
> should say what (idea) the variable represents in the program; this should be 
> said by the name's *meaning*. It is one of the greatest difficulties in 
> programming. How would you define what these variables represent, using 
> everyday language? My own definitions would lead me to choose the following 
> variable names:
> guess_text   = raw_input(promt)
> guess_number = int(user_guess)
> return guess_number
> Note: it is especially obviuos that these are 2 separate numbers, since they 
> do not even are of the same type (a piece of text, or "string", vs a number, 
> here an "int").
> 
> Good naming is very, very hard; differences of naming can make some piece of 
> program nearly trivial or instead nearly impossible to understand; often bad 
> naming is worse than hypothetical randomly chosen names, because bad naming 
> *misleads* your thinking.
> 
> Changing the value of a local variable is always, or nearly, a sign that 
> there are here 2 ideas which should be represented by 2 variables with 2 
> names. Example of 2 programming styles (note the difference in ease of 
> understanding, even if you don't know the python features used here):
> 
> def get_data (data):
>data = File(data)  # (a file)
>data = data.read() # (a piece of text)
>data = data.split("")  # (a list of words)
>return data
> ...
> data = get_data("data.text")
> 
> def data_words (file_name):
>data_file = File(file_name)# (a file)
>text = data_file.read()# (a piece of text)
>words = text.split(" ")# (a list of words)
>return words
> ...
> words = data_words("data.text")
> 
> (A special case is loop variables, but even then you only write the 
> assignment once, the value chages across multiple passes on the same code. 
> The only real exception is accumulators, like for computing a sum, which need 
> to be first initialised to a start value, often 0.)
> 
>> def print_hints(secrets, guess):
>> secret_number = secret
>> guess = guess
>> if guess < 0 or user_guess> 101:
>> print "Out of range!"
> 
> Parameters are input variables. Once they are given execution values by a 
> call like
>print_hints(input_value1, input_value2)
> 
> these variables exist _inside_ the function body (each with a name and a 
> value). As if functions were defined like:
>def print_hints:   # note: no param
>secret = input_value1
>guess  = input_value2
>... use these variables ...
> This is more or less what the language does for you. This is the whole point 
> of defining parameters, in fact. So, _you_ do not need to _rebind_ parameters 
> to local variables; they already are local variables.
> 
> In addition, you are not consistent with variable _names_, evendently, so 
> your programs have no chance to work. This is an annoying, but necessary part 
> of programming. But the language will always tell about such errors, at once, 
> *if and only if* the wrong name does *not* otherwise exist. --> pay attention!
> 
>> def main():
>> print_description()
>> secret = randrange(1,101)
>> current_guess = get_guess(1)
>> if current_guess != secret:
>> print_hints(secret_number, guess)
>> current_guess = get_guess(2)
> 
> * 'secret_number' appears from nowhere: pay attention!
> * To be more coherent checking if the guess is right or wrong (or too high or 
> too low) should be done in function print_hints as well. This function 
> _evaluates_ the guess (maybe it should be renamed).
> 
>> if secret == current_guess:
>> print "Congratulations, you win!"
>> else:
>> print "Please play again"
>> print "The secret number was", secret
> 
> These are (also) hints to the player, actually, aren't they?

***Wow, thanks a lot Denis!!  Although I didn’t get everything you said I 
definitely understand a lot more!

I’ve made some changes and have a couple questions, I’ll speak in between the 
code.  Thanks again everyone, especially for your patients, I know I’ve made 
several mistakes and I don’t know anything about programming and even less 
about these forums.  I apologize about that and again appreciate your 
patients!!!


from random import randrange
randrange(1, 101)
from random import seed
seed(129)
def print_description():
print """Welcome to Guess the Number.
I have selected a secret number in the range 1 ... 100.
You must guess the number within 10 tries.
I will tell you if you are high or low, and
I will tell you if you are hot or cold.\n"""
   
So, this is what I gather from the function below.  I’m basically taking the 
parameter guess_number and making it a str with prompt, then using the variable 
guess_text and turning the prompt into an int?  and returning the original 
value the user inputed?  

 

Re: [Tutor] Help with "Guess the number" script

2014-03-04 Thread Scott W Dunning

On Mar 3, 2014, at 1:51 AM, Ben Finney  wrote:
> "Bold” assumes that markup of text will survive; that's not reliable,
> since this is a text-only medium and only the plain text will reliably
> survive to all readers.
Sorry, I didn’t realize.  I’m still new to this.
> 
> You're creating a prompt string, so this is a good choice of name;
> except that its correct spelling is “prompt”.
Haha, I didn’t even catch that, thx.

> This is valuable! Thinking about what the values mean is vital to
> understanding what the program is doing, which is of course a big part
> of what you're in this to learn.
That’s where I’ve been getting the most confused, because the instructor is 
giving variables he wants used and I was having a hard time figuring out what 
some of them were doing.  I think I have a better understanding now though.
> 
>> def print_hints(secrets, guess):
>>secret_number = secret
> 
> You never use this “secret_number” name again, so the binding is
> useless. What was your intention?
I honestly don’t know, I’ve since taken that out completely.
> 
> You also never use the “secrets” parameter; and the “secret” name was
> not bound before you used it. Have you mis-spelled one of those?
> 
>>guess = guess
> 
> I don't know what the point of this no-op assignment is. What are you
> trying to do?
> 
>>if guess < 0 or user_guess> 101:
> 
> Likewise, you never bind the name “user_guess”. Where are you expecting
> it to be bound?
That was a mistake.  I’m trying to get it to print “Out of range” if the user 
guesses a number out of the range of 1-100.  
> 
> 
> I suspect at this point you've been flailing around without much
> understanding of the changes you're making. This leads to a confused
> mass of code that you can't understand or explain.
Yes, correct.
> 
> Better would be to experiment at the interactive Python prompt to test
> what these changes *do*, before putting them into your code. Reduce the
> mechanisms down to very minimal cases, and try them out; confirm your
> assumptions and guesses. Only then should you plan a change to the
> program file.
Ok that makes sense.

Thanks again!

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


Re: [Tutor] Help with "Guess the number" script

2014-03-03 Thread Scott W Dunning

This is what Im having trouble with now.  Here are the directions I’m stuck on 
and what I have so far, I’ll bold the part that’s dealing with the instructions 
if anyone could help me figure out where I’m going wrong.  

Thanks!

from random import randrange
randrange(1, 101)
from random import seed
seed(129)

def print_description():
print """Welcome to Guess the Number.
I have seleted a secret number in the range 1 ... 100.
You must guess the number within 10 tries.
I will tell you if you ar high or low, and
I will tell you if you are hot or cold.\n"""
   
def get_guess(guess_number):
promt = "(" + str(guess_number) +") Please enter a guess:"
user_guess = raw_input(promt)
user_guess = int(user_guess)
return user_guess

def print_hints(secrets, guess):
secret_number = secret
guess = guess
if guess < 0 or user_guess> 101:
print "Out of range!"

def main():
print_description()
secret = randrange(1,101)
current_guess = get_guess(1)
if current_guess != secret:
print_hints(secret_number, guess)
current_guess = get_guess(2)

if secret == current_guess:
print "Congratulations, you win!"
else:
print "Please play again"
print "The secret number was", secret

main()
Just below the body of the get guess function, define a new function named 
print hints that takes two arguments. The first is a secret num- ber and is 
kept in a parameter named secret. The second is a guess made by the user and it 
is held in a parameter named guess.

The user’s guess is supposed to be within the range 1 ... 100. Write a 
conditional statement that checks if the guess is out of that range, and if it 
is print ‘out of range’ in the body of the print hints function.

Now we are going to give the user the option to make a second guess. You must 
add code to the main function immediately after assignment statement you wrote 
for task 7.

Write a conditional statement to check if the current guess does not match the 
secret number. If the numbers to not match, in the body of the conditional 
statement you will do two things.

(a)  call print hints to give the user hints,

(b)  re-assign current guess to the result of calling get guess with an

argument of 2. 

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


Re: [Tutor] Help with "Guess the number" script

2014-03-03 Thread Scott W Dunning

On Mar 2, 2014, at 12:43 AM, Ben Finney  wrote:
> 
> No, that's the opposite direction :-) Inside the ‘get_guess’ function
> you should use as many names as you need for the different purposes.
> 
> So, you have one name ‘guess_number’ bound to the function's parameter.
> Don't bind anything else to it!
> 
> Then, for the return value from ‘raw_input’, you should choose a
> different suitable name and bind that name to the value (with an
> assignment statement).
> 
> Then, for the computed result, you should choose yet another suitable
> name, and bind *that* name to the computed value.
> 
> All these different names will make clear in the code what the meaning
> of each value is.
> 
Ok, I see.  So, I think I got a good portion of this done thanks to you guys 
and understanding the directions a little better.  I’ll post my code.  For some 
reason I’m not sure what the user_guess variable in the get_guess is actually 
doing, or if it’s even an appropriate variable name??  Also, I’m going to bold 
another part I’m struggling with about the number being out of range, I’m not 
sure I’m going in the right direction with that, mainly because it does not 
work.  Here is what I have so far…


from random import randrange
randrange(1, 101)
from random import seed
seed(129)

def print_description():
print """Welcome to Guess the Number.
I have seleted a secret number in the range 1 ... 100.
You must guess the number within 10 tries.
I will tell you if you ar high or low, and
I will tell you if you are hot or cold.\n""" 

def get_guess(guess_number):
promt = "(" + str(guess_number) +") Please enter a guess:"
user_guess = raw_input(promt)
user_guess = int(user_guess)
return user_guess

def print_hints(secrets, guess):
if guess < 0 or guess> 101:
print "Out of range!"

def main():
print_description()
secret = randrange(1,101)
current_guess = get_guess(1)

if secret == current_guess:
print "Congratulations, you win!"
else:
print "Please play again"
print "The secret number was", secret



main()
print_hints()___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 6:53 AM, spir  wrote:
> 
> I find directions very confusing. Also, they completely control you while 
> explaining about nothing, like a user manual saying "press this, turn that". 
> This is inappropriate for programming (and anything else): you need to 
> understand! You need the why's and the how's, not only the what’s.
Trust me I’m confused by the directions as well.  The point of the ‘project’ is 
to learn the conditional operators (if, else, elif).
> 
> If not enough, they seem to teach you pretty weird practices: what is the 
> point of the parameter guess_number?
guess_number is the number of guesses the user has used because there are only 
10 allowed.

So;
(1) Please enter a number
(2) Please try again:
(3) “……….”
(4) “…….."

> It is not a parameter, less so of this function, but a counter proper to the 
> game control, possibly used at the end to write "You won in [counter] 
> trials." But it is not and cannot be used as a parameter to get_guess. Also, 
> what is the point of requiring you to write this game without a loop? You 
> need a loop. If they want to teach you other notions first, they must find 
> another sample program.
We haven’t learned loops yet so he wanted us to try and just use conditional 
functions and be repetitive I guess.  I’m not even worries about that part, I’m 
just trying to get through this part first because it’s confusing me.  

I can post more of the instructions if needed too.

> 
> If the rest of the book is similar, I would encourage you to change. Maybe 
> try one of those (or why not both in //):
> 
> * Alan Gauld's "Learning to Program": a very good point is this guide teaches 
> to program, in general, *using* Python, mainly:
>  http://www.alan-g.me.uk/l2p/index.htm
> 
> * Al sweigart's "invent with python": this one teaches python & programming, 
> using games as learning material:
>  http://inventwithpython.com/
Thank you for the links!!

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


Re: [Tutor] Help with "Guess the Number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 8:57 AM, Mark Lawrence  wrote:

> On 01/03/2014 06:05, Scott Dunning wrote:
> 
> In addition to the answers you've already had, I suggest that you learn to 
> run code at the interactive prompt, it's a great way of seeing precisely what 
> snippets of code actually do.  Also use the print statement in Python 2 or 
> print function in Python 3, again a great way to observe what your code is 
> doing.
That makes sense, easier then running the script over and over.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread Scott W Dunning

On Mar 1, 2014, at 12:47 AM, Ben Finney  wrote:

> You've bound the name ‘current_guess’ to the user's input, but then do
> nothing with it for the rest of the function; it will be discarded
> without being used.
Hmm, I’m not quite sure I understand.  I got somewhat confused because the 
directions were changed a little and current_guess was removed from the 
get_guess function.  Is this more like what I should be doing?

def get_guess(guess_number):
raw_input(“Please enter a guess”)
guess_number = int(guess_number)
return (guess_number)
get_guess(1)

> 
> Then, you use the parameter ‘guess_number’, create a new integer from
> it, and return that integer. I think you've used the wrong name for the
> ‘int()’ parameter.
Well, since there are no loops allowed I’m guessing get_guess will be called 9 
times.  I believe guess_number is the number of tries the user has used.
So;
(1) Please enter a guess: 
(2) Please enter a guess:

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


[Tutor] Help with "Guess the number" script

2014-02-28 Thread Scott W Dunning
Hello, i am working on a project for learning python and I’m stuck.  The 
directions are confusing me.  Please keep in mind I’m very ne to this.  The 
directions are long so I’ll just add the paragraphs I’m confused about and my 
code if someone could help me out I’d greatly appreciate it!  Also, we haven’t 
learned loops yet so just conditional operators and for some reason we can’t 
use global variables.  


from random import randrange
randrange(1, 101)

from random import seed
seed(129)

def print_description():
print """Welcome to Guess the Number.
I have seleted a secret number in the range 1 ... 100.
You must guess the number within 10 tries.
I will tell you if you ar high or low, and
I will tell you if you are hot or cold.\n"""
   
def get_guess(guess_number):
print "(",guess_number,")""Plese enter a guess:"
current_guess = raw_input()
return int(guess_number)

def main():
print_description()
secret = 50
current_guess = 1
get_guess(1)
if current_guess != secret():
print "Congratulations you win!!"
   
main()


Here are the instructions I’m having a hard time with and just not sure I’m 
doing it correctly.  I’m not sure the get_guess function is correct and I’m a 
little lost with the secret and current_guess variable.

From within the body of the main function, immediately after the call to print 
description, create variable secret and assign it a random number between 1 and 
100, generated using the randrange function. You will need to pass two argument 
to randrange, what do you think they should be? You should be able to use the 
python help system or online python documentation to make sure you understand 
the arguments to randrange.

After the end of the body of the print description function, define a new 
global function named get guess that takes a single parameter. Name the 
parameter guess number, because it will hold the index (1, 2, 3, ..., 10) of 
current guess attempt. Make the function ask the user to enter guess using the 
raw input function. The function will return the number entered by the user, 
after it has been converted to an integer.

Return to the main function after the statement that assigned a value to the 
secret variable. In a new variable named current guess store the result of 
calling the get guess function with an argument of 1. Run your program to make 
sure it works correctly.

At the end of the main function, check if the current guess matches the secret. 
If it matches, print ‘Congratulations, you win!’. If it does not, print ‘Please 
play again!’ 





Thanks again!!!




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


Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning

On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote:
> which still shows a repetetive pattern and thus you can simplify it with 
> another loop. You should be able to find a way to write that loop with two
> star_row() calls on a single iteration, but can you do it with a single call 
> too?

So, I was able to cut it down a bit but I’m having a hard time trying to cut it 
down with another loop and a single call.  Wouldn’t what you’re saying in the 
above paragraph have to be another function with a loop inside?  Or are you 
saying just another loop will suffice?  Any hints?  Here is what I got so far, 
I’ll put the loop in question in bold. 

from turtle import *
from math import sin, sqrt, radians
def star(width):
R = (width)/(2*sin(radians(72)))
A = (2*width)/(3+sqrt(5))
penup()
left(18)
penup()
forward(R)
pendown()
left(162)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
penup()
left(162)
forward(R)
left(162)
   
showturtle()

def fillstar(color):
fillcolor(color)
begin_fill()
star(25)
end_fill()
red = "red"
fillstar(red)

def space(width):
penup()
forward(2*width)
pendown()

space(25)

def row(width):
penup()
right(90)
forward(width)
right(90)
forward(11*width)
right(180)
pendown()

def star_row(numberstars):
for i in range (numberstars):
fillstar(red)
space(25)

star_row(5)
row(25)
star_row(5)
row(25)
star_row(6)
row(25)
star_row(5)
row(25)
star_row(6)
row(25)
star_row(5)
row(25)
star_row(6)
row(25)
star_row(5)
row(25)
star_row(6)


This is what I’m thinking…

for I in range(4)
star_row(5)
row(25)
star_row(6)
row(25)


  Am I at all close?


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


Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning

On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote:
> If you want to make rows with more or less stars, or stars in other colors 
> you could add parameters:
> 
> def star_row(numstars, starcolor):
>for i in range(numstars):
>fillstar(starcolor)
>space(25)
> 
> Your code will then become
> 
> star_row(6, red)
> row(25)
> star_row(5, red)
> row(25)
> 
I have a question with the above loop function.  Why couldn’t row(25) be added 
into the function so that wouldn’t have to placed in between every star_row()?
> 
> which still shows a repetetive pattern and thus you can simplify it with 
> another loop. You should be able to find a way to write that loop with two
> star_row() calls on a single iteration, but can you do it with a single call 
> too?
Not sure I understand what you mean in the above paragraph?  


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


Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning
On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote
> a programmer would think "for loop” immediately
That’s what I thought.  It just seemed like way to much to keep repeating 
everything over and over.  I knew there had to be a better way we just haven’t 
learned loops in school yet.  
> 
> for i in range(5):
>fillstar(red)
>space(25)
Awesome, I was able to cut everything down quite a bit but, now like you say 
below I’m still repeating the loop.  I’m gonna see if I can make a function 
with the loop to cut it down even further.  

Here is what I was able to cut it down to so far with your help.  I’ll paste 
the new code when I make a function with the loop and maybe you guys can help 
me see if it look any better/easier.  

Also, does anyone know anything about turtle where I can try and move the 
starting point to the upper left hand corner?  

Thanks again!
Scott


from turtle import *
from math import sin, sqrt, radians

def star(width):
R = (width)/(2*sin(radians(72)))
A = (2*width)/(3+sqrt(5))
penup()
left(18)
penup()
forward(R)
pendown()
left(162)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
penup()
left(162)
forward(R)
left(162)

showturtle()

def fillstar(color):
fillcolor(color)
begin_fill()
star(25)
end_fill()

red = "red"
fillstar(red)

def space(width):
penup()
forward(2*width)
pendown()

space(25)

for i in range (5):
fillstar(red)
space(25)

def row(width):
penup()
right(90)
forward(width)
right(90)
forward(11*width)
right(180)
pendown()
row(25)

for i in range (5):
fillstar(red)
space(25)

row(25)

for i in range (6):
fillstar(red)
space(25)

row(25)

for i in range (5):
fillstar(red)
space(25)

row(25)

for i in range (6):
fillstar(red)
space(25)

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


Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning

On Feb 23, 2014, at 5:31 AM, Dave Angel  wrote:
> 
> Welcome to the tutor forum also, Scott.  You'll find it works very
> similarly to python-list,  and has many of the same people on it.
> I'm not sure how you tried to attach source,  but please be aware
> that this is a text list - anything other than plain text will
> probably be invisible or inconvenient to someone. Just paste
> snippets inline when needed. 
I actually forgot to paste the code before I sent the email.

> 
> What you're looking for is a loop. for and while are the two
> keywords for looping.  In this case,  since you know how many
> times you want to go round, loop is appropriate. Build a
> collection or iterator of length 5, and loop over it. range is
> designed for the purpose:
> 
> for index in range (5):
> dosomething
> moresomething (index)
Thank you for this help.  I believe I understand.  At least enough to do a 
simple loop for what I need.  I’ll check back and paste my code after and maybe 
you can tell me if there is anything I could be doing better/easier.  

Thanks again!!

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


Re: [Tutor] Function help

2014-02-23 Thread Scott W Dunning

On Feb 23, 2014, at 1:12 AM, Scott W Dunning  wrote:

> I am VERY new to python (programming too).  I had a question regarding 
> functions.  Is there a way to call a function multiple times without 
> recalling it over and over.  Meaning is there a way I can call a function and 
> then add *5 or something like that?  I am trying to code an American Flag 
> using turtle for class so I’ll post the code I have so far below.  As you can 
> see towards the bottom I recall the functions to draw the stars, fill in 
> color and give it spacing.  I was wondering if there was a way to cut down on 
> all that some how?  
> 
> Thanks for any help!
> 
> Scott

from turtle import *
from math import sin, sqrt, radians

def star(width):
R = (width)/(2*sin(radians(72)))
A = (2*width)/(3+sqrt(5))
penup()
left(18)
penup()
forward(R)
pendown()
left(162)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
left(144)
forward(A)
right(72)
forward(A)
penup()
left(162)
forward(R)
left(162)

showturtle()

def fillstar(color):
fillcolor(color)
begin_fill()
star(25)
end_fill()

red = "red"
fillstar(red)

def space(width):
penup()
forward(2*width)
pendown()
space(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

def row(width):
penup()
right(90)
forward(width)
right(90)
forward(11*width)
right(180)
pendown()
row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)

row(25)

fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)
fillstar(red)
space(25)






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


[Tutor] Function help

2014-02-23 Thread Scott W Dunning
I am VERY new to python (programming too).  I had a question regarding 
functions.  Is there a way to call a function multiple times without recalling 
it over and over.  Meaning is there a way I can call a function and then add *5 
or something like that?  I am trying to code an American Flag using turtle for 
class so I’ll post the code I have so far below.  As you can see towards the 
bottom I recall the functions to draw the stars, fill in color and give it 
spacing.  I was wondering if there was a way to cut down on all that some how?  

Thanks for any help!

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


Re: [Tutor] help with regexps/filename parsing

2005-01-31 Thread Scott W
Slight correction which I realized after sending, see below for 
version/release seperation, which I should have seen but blame lack of 
sleep ;-)

Scott W wrote:
Hey all.
I've got an issue that's been driving me a bit nuts.  I'm sure it _can_ 
be done with a regexp, although I'm missing a piece needed to tie it 
together to work for all cases.

I need to parse out a list of RPMs in this case, but it seems the RPM 
naming convention has changed, as there are files I'll need to parse 
that are NOT in the normal name-version-release.arch.rpm format.

I need to be able to grab the 'basename' for each file, as well as the 
version and arch, although these can be done seperately.  The problem 
can be shown by the following list of filenames:

XFree86-ISO8859-15-75dpi-fonts-4.3.0-78.EL.i386.rpm(Note the EL 
embedded in name)
xfig-3.2.3d-12.i386.rpm(standard naming)
rhel-ig-ppc-multi-zh_tw-3-4.noarch.rpm
perl-DateManip-5.42a-0.rhel3.noarch.rpm
openoffice.org-style-gnome-1.1.0-16.9.EL.i386.rpm

Those should represent the set of variations now possible.  I can handle 
most, but not all of the cases...any suggestions that would cover all of 
the above allowing the extraction of:
basename- in this case:
XFree86-ISO8859-15-75dpi-fonts,
xfig,
rhel-ig-ppc-multi-zh_tw,
perl-DateManip,
openoffice.org-style-gnome

version:
4.3.0-78.EL(yes, including the .EL unfortunately, although I'd 
be OK without it and munging it on end if needed)
3.2.3d-12
3-4
5.42a-0
1.1.0-16.9.EL
corrected versions:
4.3.0
3.2.3d
3
5.42a
1.10
(new) releases:
78.EL
12
4
0
16.9.EL

arches:
i386,
i386,
noarch,
noarch,
i386
respectively.
Any help greatly appreciated, as I've been beating myself up on this one 
for a bit.

Thanks,
Scott
___
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 with regexps/filename parsing

2005-01-31 Thread Scott W
Hey all.
I've got an issue that's been driving me a bit nuts.  I'm sure it _can_ 
be done with a regexp, although I'm missing a piece needed to tie it 
together to work for all cases.

I need to parse out a list of RPMs in this case, but it seems the RPM 
naming convention has changed, as there are files I'll need to parse 
that are NOT in the normal name-version-release.arch.rpm format.

I need to be able to grab the 'basename' for each file, as well as the 
version and arch, although these can be done seperately.  The problem 
can be shown by the following list of filenames:

XFree86-ISO8859-15-75dpi-fonts-4.3.0-78.EL.i386.rpm		(Note the EL 
embedded in name)
xfig-3.2.3d-12.i386.rpm		(standard naming)
rhel-ig-ppc-multi-zh_tw-3-4.noarch.rpm
perl-DateManip-5.42a-0.rhel3.noarch.rpm
openoffice.org-style-gnome-1.1.0-16.9.EL.i386.rpm

Those should represent the set of variations now possible.  I can handle 
most, but not all of the cases...any suggestions that would cover all of 
the above allowing the extraction of:
basename- in this case:
	XFree86-ISO8859-15-75dpi-fonts,
	xfig,
	rhel-ig-ppc-multi-zh_tw,
	perl-DateManip,
	openoffice.org-style-gnome

version:
	4.3.0-78.EL	(yes, including the .EL unfortunately, although I'd be OK 
without it and munging it on end if needed)
	3.2.3d-12
	3-4
	5.42a-0
	1.1.0-16.9.EL

arches:
i386,
i386,
noarch,
noarch,
i386
respectively.
Any help greatly appreciated, as I've been beating myself up on this one 
for a bit.

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


[Tutor] Changing (Unix) environment for python shell/popen() commands

2005-01-23 Thread Scott W
Hey all.
I'm unfortunately stuck using python 1.5.2, primarily on Linux 
currently, and have done the usual searching (on list, active state, 
google), without luck.

I've got to shell out from my python code to execute a command, but 
_must_ set the environment at the same time (or prior to execution).  I 
say must, because in this case the obvious answer of modifying the 
command to be called or wrapping it with a shell script to set the 
environment won't work/isn't going to happen.

I saw some comments about setting os.environ[], but 
didn't seem to be seeing this work in subsequent calls using popen2().

Does anyone have a working piece of code setting some env variable 
successfully prior to(or along with) calling popen2() (or friends).

Also, is there any way to get the called programs return code via 
popen() (again, under python 1.5.2)?

I know this has been asked often enough, but once again, it seems I'm 
left wanting for _good_ documentation under python (ie compared to man 
pages, DevStudio Win32 docs, Linux info, Java docs, etc), including the 
half dozen python books I own  (great for some things, but no reference 
whatsoever to other things that I'd think would warrant some coverage)..

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


Re: [Tutor] replacement for constants from other languages in Python?

2005-01-06 Thread Scott W
Kent Johnson wrote:
Scott W wrote:
The 'need' to define a global constant in an imported module, for 
example- (I know about sys.version_info, but it doesn't exist in 
1.5.2...don't ask ;-)  I also know this could be handled via a class, 
but what is the equivalent of the following snippets?  Not so 
interested in style comments (I am, but not on these/this thread ;-) 
as much as other ways to do this..

1.
ourversion.py:
import sys
MINVERSION = 1.5

This is the usual Python way. Python's approach generally is 'treat your 
users like adults', i.e. give them the information needed to make 
sensible decisions, but don't try to keep them from doing something you 
think is stupid. Putting the name in upper case gives the information 
that this is intended to be a constant.
Sure, if I can't make it a true constant value, might as well make it
'obvious' ;-)
def checkVersion():
""" used as an evil hack because 1.5.2 doesn't have
sys.version_info
"""

# Not sure why, but declaring MINVERSION as repr(foo) in the
# first place doesn't work, something about python type handling
# I'm sure..

MINVERSION = repr(1.5)
should work just fine. It will give the same result as the more readable
MINVERSION = '1.5'
Ok, this would make a bit more sense RE: repr()- in one of the resources
I found, it seemed to state that repr(x) was converting x into a numeric
representation, ala atoi() and friends.  Obviously, this is the opposite
of what I'd actually wanted.  The sample snippets I put in had a
duplicated repr() if not more than one, which wasn't doing what I
expected anyways (although at which point I was essentially comparing
strings of similar length, getting 'a' result, just not the intended one ;-)

I'm not sure why you are using repr() so much.
return repr(MINVERSION) >= repr(getVersion())
def getVersion():
return sys.version[0:3]
if repr(getVersion() < 2.0)

This will certainly not do what you want for two reasons.
- getVersion() returns a string, you are comparing it to a float which 
will not give a meaningful result.
- In Python < 2.3 the result of the comparison will be an integer 0 or 
1. repr() converts this to a *string* '0' or '1' which will *always* 
evaluate as True!!
Yep, see above...wish I knew where I saw that 'explanation' of repr()
and str()
# boo, we have no builtin bool
global True
[snip]
Rather than testing the version, you can test directly to see whether 
True and False are defined. If not, you can add them to the __builtin__ 
module and they will be globally available. Here is one way:

import __builtin__
if not __builtin__.hasattr('True'):
   __builtin__.True = 1
if not __builtin__.hasattr('False'):
   __builtin__.False = 0
OK, that's helpful.  I can see the advantages of several of python's
mechanisms, such as dir() as well as treating everything like an
'interactive object to determine existing methods and attributes (dir()
and your example of hasattr().  Pretty cool...now to go from libc/POSIX
to an entirely new and (mostly) different set of core libs and
functionality.. ;-)  Actually, that IS pretty nice, can perhaps take the
place of some(most?) of features.h, unistd.h and friendswhich is
really what I want, regardless of the example...or having to 'roll my
own'.  Very cool.
This suggestion is taken from this thread on comp.lang.python:
http://tinyurl.com/46me3
Note that adding names to __builtin__ is NOT recommended in general! 
Don't use this to create your own global constants! It is OK in this 
case because to duplicate Python 2.3 behaviour you need a true global.

The other oddity is without being able to define a 'real' constant, as 
in #DEFINE MINVERSION 1.5,

the scope of MINVERSION (and True/False) even using the global keyword 
still uses the ocal file's namespace.  I don't want to debate the 
merits of using globals...most people that claim they never use any in 
other languages _still_ use constants in header files, which is the 
purpose I'd like to be able to do generally

The usual Python solution is to make a module containing constant 
definitions and import it where you need them.

[snip]
or, if you want to import all the constants directly,
# Client2.py
from Constants import *
There was my catch/issue I was having.  I expected the global keyword
being used in my previous bool/True/False definition to put it into a
global namespace, but I still had a namespace issue as you explained
here- simply doing an 'import ' will allow access to variables
created as globals in that module, but not without scope resolution, ie
module.True, module.MINVERSION, etc...what I expected was anything
declared as global to simply be in the global namespace of any other
module importing t

[Tutor] replacement for constants from other languages in Python?

2005-01-06 Thread Scott W
Hey all,
I've done the usual googling, checked the Learning Python book and did 
some list searches, to no avail as of yet.

I'm _very_ used to using C style constants (preprocessor #define 
directives) or C++ const keyword style, for a variety of reasons.

I've yet to see anything covering 'how to work around the lack of 
constants in Python'...can anyone point me in the right direction here?

A few examples/reasons for use:
The 'need' to define a global constant in an imported module, for 
example- (I know about sys.version_info, but it doesn't exist in 
1.5.2...don't ask ;-)  I also know this could be handled via a class, 
but what is the equivalent of the following snippets?  Not so interested 
in style comments (I am, but not on these/this thread ;-) as much as 
other ways to do this..

1.
ourversion.py:
import sys
MINVERSION = 1.5
def checkVersion():
""" used as an evil hack because 1.5.2 doesn't have 
 
sys.version_info
"""
# Not sure why, but declaring MINVERSION as repr(foo) in the
# first place doesn't work, something about python type handling
# I'm sure..
return repr(MINVERSION) >= repr(getVersion())
def getVersion():
return sys.version[0:3]
if repr(getVersion() < 2.0)
# boo, we have no builtin bool
global True
global False
True = 1
False = 0
funkyScopeAndConstants.py:
import ourversion.py
import sys
import os
import 
...
...
if someOtherModule.property = True
# do something
You get the point.
The other oddity is without being able to define a 'real' constant, as 
in #DEFINE MINVERSION 1.5,

the scope of MINVERSION (and True/False) even using the global keyword 
still uses the ocal file's namespace.  I don't want to debate the merits 
of using globals...most people that claim they never use any in other 
languages _still_ use constants in header files, which is the purpose 
I'd like to be able to do generallynot to mention the fact that I 
really am _not_ thrilled with the use of string literals typed in each 
time in code (yes, quick and dirty code but still) I see seems to be 
'OK' in python for the use of comparisons...opposed to something like

if(strncmp(strVal,
CONSTANT_STRING_VAL_LIKE_HTTP_ACCEPT_ENCODING_HEADER,
strlen(strVal)
{
do_something();
}
or
if(floatVal > PI)
{
do_something()
}
ok, hopefully that's explaining some of why I'd like a 'constant 
equivalent' as well as a question on global scoping/python namespaces.

A last question would also be if the equivalent of __FILE__ and __LINE__ 
macros exist?

Thanks,
Scott

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