[Tutor] Borg di borg di borg (or: Swedish chef)

2012-09-24 Thread Albert-Jan Roskam
Hi Pythonistas,

I have three classes, Generic, Test and Test2. Generic contains a load method 
that loads a file. This may only be done once, as a file_read_open error is 
returned if the file is open already and an attempt is made to re-open it. The 
file may be opened from Test or Test2. After a lot of playing with a "counter" 
class variable, I realized this may be a legitimate use case for the Borg 
pattern (http://code.activestate.com/recipes/66531). Is the code below the 
right way to apply the Borg pattern?


somefile = "/home/albertjan/Desktop/somefile.txt"

class Borg(object):

    counter = 0
    _state = {}

    def __init__(self):
    self.__dict__ = self._state

class Generic(Borg):
    
    def __init__(self):
    super(Generic, self).__init__()
    self.loaded = self.load()
    print "@state", Borg._state
    print self.loaded
    
    def load(self):
    """ Only one file at a time may be opened, or else
    there will be an open-read error"""
    Borg.counter += 1
    return open(somefile)

class Test(Generic):
    
    def __init__(self):
    if Borg.counter == 0:
    self.theFile = Generic().load()
    self.theFile = Borg._state["loaded"]
    print self.theFile

class Test2(Generic):

    def __init__(self):
    if Borg.counter == 0:
    self.theFile = Generic().load()   
    self.theFile = Borg._state["loaded"]
    print "---", self.theFile
    print Borg.counter
    

b2 = Test2()
b1 = Test()


Thank you in advance!

Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
 ~~ 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Borg di borg di borg (or: Swedish chef)

2012-09-24 Thread Peter Otten
Albert-Jan Roskam wrote:

> Hi Pythonistas,
> 
> I have three classes, Generic, Test and Test2. Generic contains a load
> method that loads a file. This may only be done once, as a file_read_open
> error is returned if the file is open already and an attempt is made to
> re-open it. The file may be opened from Test or Test2. After a lot of
> playing with a "counter" class variable, I realized this may be a
> legitimate use case for the Borg pattern
> (http://code.activestate.com/recipes/66531). Is the code below the right
> way to apply the Borg pattern?

What do you gain from that complexity? Even

assert b1.load() is b2.load()

will fail. So why not keep it simple?

_file = None
def load_file():
global _file
if _file is None:
_file = open(somefile)
return _file

(if you are using multiple threads you have to add a lock)
Of course you can bypass this "safety" measure by doing 

open(somefile)

anywhere in your code, so it is more like a gentleman's agreement between 
you and yourself not to tread over the red line.

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


[Tutor] running program in terminal

2012-09-24 Thread Benjamin Fishbein
Hello. I can run programs in IDLE but when I try to do it in a terminal or with 
textwrangler, it usually just logs out and says it's completed, but the program 
hasn't been run. This is particularly so when the program uses urllib. I'm 
using OS X. 

logout

[Process completed]

That's what it prints.
Any idea what to do?
Ben

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


Re: [Tutor] Sudoku

2012-09-24 Thread Walter Prins
Mark,

On 23 September 2012 22:53, Mark Lawrence  wrote:
>> Is the personal sniping really necessary?  (That's a rhetorical
>> question, just to be clear.)
>
> Well if Dwight insists on replying to something without quoting the context
> so the rest of us haven't the faintest idea what he's talking about what are
> we meant to do?  Sadly my mind reading capabilities are quite low, I don't
> know about that for anyone else.

Well then tell him how to do it properly and/or provide a better
answer without the personal invective.  No one expects you to read
minds obviously, but the personal attacks and sarcasm are really way
out of line.  I can only hang my head in shame at what Myles must be
thinking of all this.  So childish.

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


Re: [Tutor] Borg di borg di borg (or: Swedish chef)

2012-09-24 Thread eryksun
On Mon, Sep 24, 2012 at 6:02 AM, Albert-Jan Roskam  wrote:
>
> I have three classes, Generic, Test and Test2. Generic contains a load
> method that loads a file. This may only be done once, as a
> file_read_open error is returned if the file is open already and an
> attempt is made to re-open it. The file may be opened from Test or Test2.

What's the context here? Is "file_read_open error" an error code
returned by a library? If so, I'd pass it on by raising an exception
instead of masking the error.

As to the Borg pattern, it seems to me you don't actually need a
'Borg' base class. But if you do, then you probably also want to
override _state with a new dict for each subclass. You can do this
automatically with a custom descriptor, a metaclass, or even a simple
property like the following:

class Borg(object):
_all_state = {}

def __init__(self):
self.__dict__ = self._state

@property
def _state(self):
return self._all_state.setdefault(self.__class__, {})


class Generic(Borg):

def __init__(self):
super(Generic, self).__init__()
self.loaded = None

def load(self, filename):
""" Only one file at a time may be opened, or else
there will be an open-read error"""
if self.loaded is None:
self.loaded = open(filename)
return self.loaded
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running program in terminal

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 17:41, Benjamin Fishbein  wrote:

> Hello. I can run programs in IDLE but when I try to do it in a terminal or
> with textwrangler, it usually just logs out and says it's completed, but
> the program hasn't been run. This is particularly so when the program uses
> urllib. I'm using OS X.
>
> logout
>
> [Process completed]
>

Are you using the python launcher? Or are you opening a terminal and then
typing 'python myscript.py'?

Tell me if the following steps work for you:

1) Open the terminal - you can find it under Applications/Utiltiies (or if
you just type 'terminal' in spotlight). You should see something like:
Last login: Tue Mar 6 17:21:36 on console
Welcome to Darwin!
ibook:~ Alex$

2) Type 'cd name/of/folder' and hit enter to move into the folder that
contains your Python script.

3) Type 'python myscript.py' and hit enter to run the script called
'myscript.py'.

Oscar

About the terminal:
http://macapper.com/2007/03/08/the-terminal-an-introduction/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sudoku

2012-09-24 Thread Mark Lawrence

On 24/09/2012 17:52, Walter Prins wrote:

Mark,

On 23 September 2012 22:53, Mark Lawrence  wrote:

Is the personal sniping really necessary?  (That's a rhetorical
question, just to be clear.)


Well if Dwight insists on replying to something without quoting the context
so the rest of us haven't the faintest idea what he's talking about what are
we meant to do?  Sadly my mind reading capabilities are quite low, I don't
know about that for anyone else.


Well then tell him how to do it properly and/or provide a better
answer without the personal invective.  No one expects you to read
minds obviously, but the personal attacks and sarcasm are really way
out of line.  I can only hang my head in shame at what Myles must be
thinking of all this.  So childish.

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



Dwight Hutto refers to my family as pigs and you have a go at me, what a 
downright bloody check.  We're here to teach Python.  If he's too thick 
to understand context he can search the web for the word or resort to a 
dictionary.


--
Cheers.

Mark Lawrence.

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


[Tutor] BMI Question

2012-09-24 Thread Aija Thompson

Hi!
So I've been working on this question for hours! And Python keeps giving me an 
error saying that my syntax for BMI is wrong. I really can't understand why. 
So this is what I have so far:
w = raw_input('Please give your weight in lbs: ')h = raw_input('Now your height 
in feet and inches: ')h. split("'")ft, inches = h. split("'")h_sum = 
float(12*int(ft)) + (int(inches.strip('"'))BMI = 
float(703*w)/float(h_sum*h_sum)print 'Your BMI is: ', BMI
It's the first BMI that isn't agreeing with Python. Any help would do!
Also, if there are any other serious problems, maybe you could let me know. I'm 
still having some trouble learning all of this. 
Thanks!   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sudoku

2012-09-24 Thread Aija Thompson

I'm sorry, I have no idea how this has any reference to my Python question...

> To: tutor@python.org
> From: breamore...@yahoo.co.uk
> Date: Mon, 24 Sep 2012 20:16:39 +0100
> Subject: Re: [Tutor] Sudoku
> 
> On 24/09/2012 17:52, Walter Prins wrote:
> > Mark,
> >
> > On 23 September 2012 22:53, Mark Lawrence  wrote:
> >>> Is the personal sniping really necessary?  (That's a rhetorical
> >>> question, just to be clear.)
> >>
> >> Well if Dwight insists on replying to something without quoting the context
> >> so the rest of us haven't the faintest idea what he's talking about what 
> >> are
> >> we meant to do?  Sadly my mind reading capabilities are quite low, I don't
> >> know about that for anyone else.
> >
> > Well then tell him how to do it properly and/or provide a better
> > answer without the personal invective.  No one expects you to read
> > minds obviously, but the personal attacks and sarcasm are really way
> > out of line.  I can only hang my head in shame at what Myles must be
> > thinking of all this.  So childish.
> >
> > Walter
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> Dwight Hutto refers to my family as pigs and you have a go at me, what a 
> downright bloody check.  We're here to teach Python.  If he's too thick 
> to understand context he can search the web for the word or resort to a 
> dictionary.
> 
> -- 
> Cheers.
> 
> Mark Lawrence.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI Question

2012-09-24 Thread Stephen Haywood
On Sep 24, 2012, at 3:16 PM, Aija Thompson  wrote:

 Hi!

So I've been working on this question for hours! And Python keeps giving me
an error saying that my syntax for BMI is wrong. I really can't understand
why.

So this is what I have so far:

w = raw_input('Please give your weight in lbs: ')
h = raw_input('Now your height in feet and inches: ')
h. split("'")

   ^
This doesn't seem necessary.

ft, inches = h. split("'")
h_sum = float(12*int(ft)) + (int(inches.strip('"'))

   ^
You have three opening parents on this line and only two closing parens.

BMI = float(703*w)/float(h_sum*h_sum)
print 'Your BMI is: ', BMI

It's the first BMI that isn't agreeing with Python. Any help would do!

Also, if there are any other serious problems, maybe you could let me know.
I'm still having some trouble learning all of this.

Thanks!

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


[Tutor] Python Assignment Question

2012-09-24 Thread Aija Thompson

Hi! 
I've been working on this question for a long time and for some reason it's 
just not clicking. 
I'm not sure if my loop for the question is the right one, or if I'm even on 
the right track.
We're supposed to make a program that counts the number of days into the year 
it is if you input a date. Not including leap years. 
This is what I have so far:
months = 'January, February, March, April, May, June, July, August, September, 
October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 
31, 30, 31' #shorterMonths = 'February, April, 
June, September, Novmeber'#longerMonths = 'January, March, May, July, August, 
October, December'
month = raw_input('Enter the month: ')day = raw_input('Enter the day: ')
for x in month:whichMonth = months.index(x)monthNumber = 
daysPerMonth[whichMonth]dayYear.append(monthNumber)
I was hoping to make a loop that would check which month it is and compare it 
to the second list I made with the number of days in that month. I don't know 
if I've made that clear to the program or not. Either way, I feel pretty lost 
at the moment. 
Any help would do! 
Thanks!   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sudoku

2012-09-24 Thread Mark Lawrence

On 24/09/2012 20:15, Aija Thompson wrote:


I'm sorry, I have no idea how this has any reference to my Python question...



Please accept my apologies for getting completely off topic on your thread.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] BMI Question

2012-09-24 Thread eryksun
On Mon, Sep 24, 2012 at 3:13 PM, Aija Thompson  wrote:
>
> ft, inches = h. split("'")
> h_sum = float(12*int(ft)) + (int(inches.strip('"'))

Leave h_sum as an int:

h_sum = 12 * int(ft) + int(inches.strip('"'))

A better name here would be "h_inch". Also, make sure your parentheses
are closed. You have an extra left parenthesis in your expression. A
good editor will highlight matching parentheses.

> BMI = float(703*w)/float(h_sum*h_sum)

w is a string. Multiplying a string by N gives you a new string
containing N copies. For example, 703 copies of "180" is a number
string beyond the range of a float, so the result is inf (infinity).
You need to convert w to an int before multiplying. Also, the
expression is evaluated from left to right (based on standard order of
operations) and will return a float if you start with the constant
703.0. For example 703.0 * 180 / (72 * 72) == 24.409722.

Here's the revised expression:

BMI = 703.0 * int(w) / (h_sum * h_sum)

Finally, you can round the BMI before printing, say to 2 decimal places:

print 'Your BMI is:', round(BMI, 2)

But using string formatting would be better:

print 'Your BMI is: %.2f' % BMI
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI Question

2012-09-24 Thread Prasad, Ramit
Aija Thompson wrote:
> Hi!
> 
> So I've been working on this question for hours! And Python keeps giving me an
> error saying that my syntax for BMI is wrong. I really can't understand why.
> 
> So this is what I have so far:


One suggestion: immediately convert to appropriate number type 
instead of storing the string values. It lets you know in the 
appropriate spot if there was a problem with the input
instead of hiding it for later when you actually use the
values.

> 
> w = raw_input('Please give your weight in lbs: ')
> h = raw_input('Now your height in feet and inches: ')
> h. split("'")

This line does nothing since the result of h.split("'")

> ft, inches = h. split("'")

ft = int(h.split("'")[0])
inches = int(h.split("'")[1].split('"')[0].strip())
weight = float(w) # or int?


> h_sum = float(12*int(ft)) + (int(inches.strip('"'))

Stephen already commented on your syntax error on the line above.

h_sum = 12.0 * ft + inches # The .0 will force float multiplication

> BMI = float(703*w)/float(h_sum*h_sum)

The above line fails because you never converted `w` to a number.
In addition, you do not need to convert everything to a float.
One float in the equation should mean that Python returns
the result of that equation as a float.

BMI = 703.0 * weight / h_sum**2

> print 'Your BMI is: ', BMI
> 
> It's the first BMI that isn't agreeing with Python. Any help would do!
> 
> Also, if there are any other serious problems, maybe you could let me know.
> I'm still having some trouble learning all of this.
> 
> Thanks!


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Mark Lawrence

On 24/09/2012 20:20, Aija Thompson wrote:


Hi!
I've been working on this question for a long time and for some reason it's 
just not clicking.
I'm not sure if my loop for the question is the right one, or if I'm even on 
the right track.
We're supposed to make a program that counts the number of days into the year 
it is if you input a date. Not including leap years.
This is what I have so far:
months = 'January, February, March, April, May, June, July, August, September, 
October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 
31, 30, 31' #shorterMonths = 'February, April, 
June, September, Novmeber'#longerMonths = 'January, March, May, July, August, 
October, December'
month = raw_input('Enter the month: ')day = raw_input('Enter the day: ')
for x in month:whichMonth = months.index(x)monthNumber = 
daysPerMonth[whichMonth]dayYear.append(monthNumber)
I was hoping to make a loop that would check which month it is and compare it 
to the second list I made with the number of days in that month. I don't know 
if I've made that clear to the program or not. Either way, I feel pretty lost 
at the moment.
Any help would do!
Thanks! 


Your code is basically unreadable in Thunderbird but as I pinched 
another of your threads I've had a go at untangling it.


What you're doing is getting an index into a string.  You want to get an 
index into a list.  You can also simplfy the whole structure so search 
the web for "python two dimensional lists", without the quotes of course.


HTH.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 3:20 PM, Aija Thompson  wrote:
> Hi!
>
> I've been working on this question for a long time and for some reason it's
> just not clicking.

Algorithm is the appropriate approach. That's what makes it click.

>
> I'm not sure if my loop for the question is the right one, or if I'm even on
> the right track.
>
> We're supposed to make a program that counts the number of days into the
> year it is if you input a date. Not including leap years.

We'll leave leap years alone for now then, but there are special years
for that input which could be used as a count variable.

>
> This is what I have so far:
>
> months = 'January, February, March, April, May, June, July, August,
> September, October, November, December'
> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'
>
> #shorterMonths = 'February, April, June, September, Novmeber'
> #longerMonths = 'January, March, May, July, August, October, December'

I'd suggest using a dictionary with the month as the
identifier(month_dict = {'january' : 31, 'february': [28,29]}, and an
integer as the value for each static count of months.

>
> month = raw_input('Enter the month: ')
> day = raw_input('Enter the day: ')
>
> for x in month:
> whichMonth = months.index(x)
> monthNumber = daysPerMonth[whichMonth]
> dayYear.append(monthNumber)
>
> I was hoping to make a loop that would check which month it is and compare
> it to the second list I made with the number of days in that month. I don't
> know if I've made that clear to the program or not. Either way, I feel
> pretty lost at the moment.
>
> Any help would do!
>
> Thanks!
>

But in the end, you just want to count days.
So you could iterate through the dictionary's values_of days in each
month, up until the month and the date matches(loop stops), while
using a day_count += 1 in the loop.

Just check for the value of the month, and the number of the day to
stop the loop count.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 4:24 PM, Dwight Hutto  wrote:
> On Mon, Sep 24, 2012 at 3:20 PM, Aija Thompson  
> wrote:
>> Hi!
>>
>> I've been working on this question for a long time and for some reason it's
>> just not clicking.
>
> Algorithm is the appropriate approach. That's what makes it click.
>
>>
>> I'm not sure if my loop for the question is the right one, or if I'm even on
>> the right track.
>>
>> We're supposed to make a program that counts the number of days into the
>> year it is if you input a date. Not including leap years.
>
> We'll leave leap years alone for now then, but there are special years
> for that input which could be used as a count variable.
>
>>
>> This is what I have so far:
>>
>> months = 'January, February, March, April, May, June, July, August,
>> September, October, November, December'
>> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'
>>
>> #shorterMonths = 'February, April, June, September, Novmeber'
>> #longerMonths = 'January, March, May, July, August, October, December'
>
> I'd suggest using a dictionary with the month as the
> identifier(month_dict = {'january' : 31, 'february': [28,29]}, and an
> integer as the value for each static count of months.
>
>>
>> month = raw_input('Enter the month: ')
>> day = raw_input('Enter the day: ')
>>
>> for x in month:
>> whichMonth = months.index(x)
>> monthNumber = daysPerMonth[whichMonth]
>> dayYear.append(monthNumber)
>>
>> I was hoping to make a loop that would check which month it is and compare
>> it to the second list I made with the number of days in that month. I don't
>> know if I've made that clear to the program or not. Either way, I feel
>> pretty lost at the moment.
>>
>> Any help would do!
>>
>> Thanks!
>>
>
> But in the end, you just want to count days.
> So you could iterate through the dictionary's values_of days in each
> month, up until the month and the date matches(loop stops), while
> using a day_count += 1 in the loop.
>

Or just count each month's days in the loop, and then when you hit the
month, add the days to the adding of the previous months, which just
would increment based on the dictionary's value, instead of a 1 count
loop, you get an addition of the months prior to the date, plus how
many days into the current month you want to find how many days into
the year you are.

For leap year just use a standard year, and if that year jn the input,
or every 4 years past that, add in 1 day.

> Just check for the value of the month, and the number of the day to
> stop the loop count.
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Prasad, Ramit
Aija Thompson wrote:
> Hi!
> 
> I've been working on this question for a long time and for some reason it's
> just not clicking.
> 
> I'm not sure if my loop for the question is the right one, or if I'm even on
> the right track.
> 
> We're supposed to make a program that counts the number of days into the year
> it is if you input a date. Not including leap years.
> 
> This is what I have so far:
> 
> months = 'January, February, March, April, May, June, July, August, September,
> October, November, December'

This is a string of months. That will not be very helpful to you.
Looking at your later code this should be a list.

months = [ 'January', 'February', ]

> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'

Same problem here, but given your months I would use a dictionary
so you can map the month to the days per month.

months = { 1 : 31, 2 : 28 }

Note the lack of quotes around 31 and 28. That means these are
Python numbers and not strings. Numbers will be more useful
while calculating. Instead of using the month names,
I figured it would be more useful to know the month number.

> 
> #shorterMonths = 'February, April, June, September, Novmeber'
> #longerMonths = 'January, March, May, July, August, October, December'
> 
> month = raw_input('Enter the month: ')
> day = raw_input('Enter the day: ')
> 
> for x in month:
>         whichMonth = months.index(x)
>         monthNumber = daysPerMonth[whichMonth]
>         dayYear.append(monthNumber)

If you iterate through months (unlike the month as written) it 
would iterate through all months regardless if x is December 
while the date input is say August.

# Untested
days = 0
month = int( raw_input( 'month: ' ) )
day_of_month = int( raw_input( 'day: ' ) )
current_month = 1
while current_month < month:
# For all months before desired month
days += months[ current_month ]
# Now add days for current month.
days += day_of_month

> 
> I was hoping to make a loop that would check which month it is and compare it
> to the second list I made with the number of days in that month. I don't know
> if I've made that clear to the program or not. Either way, I feel pretty lost
> at the moment.

Although the above should work, it is not very flexible. 
I would probably look at the date class in the datetime module.
You can use the date class to compare dates and increment the days.
This has the advantage of taking into account things like leap years 
and paves the way for calculating days between ranges (which I suspect
will be an upcoming assignment if you are a student). Of course,
this is computationally inefficient but it should be "fast enough"
and work. The pseudo-code is written below. 

while current_date < desired_date
days +=1
current_date += 1 # look at the datetime.timedelta class to do this

> 
> Any help would do!
> 
> Thanks!

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Dave Angel
On 09/24/2012 03:20 PM, Aija Thompson wrote:
> Hi! 
> I've been working on this question for a long time and for some reason it's 
> just not clicking. 
> I'm not sure if my loop for the question is the right one, or if I'm even on 
> the right track.
> We're supposed to make a program that counts the number of days into the year 
> it is if you input a date. Not including leap years. 
> This is what I have so far:
> months = 'January, February, March, April, May, June, July, August, 
> September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 
> 30, 31, 31, 30, 31, 30, 31' #shorterMonths = 
> 'February, April, June, September, Novmeber'#longerMonths = 'January, March, 
> May, July, August, October, December'
> month = raw_input('Enter the month: ')day = raw_input('Enter the day: ')
> for x in month:whichMonth = months.index(x)monthNumber = 
> daysPerMonth[whichMonth]dayYear.append(monthNumber)
> I was hoping to make a loop that would check which month it is and compare it 
> to the second list I made with the number of days in that month. I don't know 
> if I've made that clear to the program or not. Either way, I feel pretty lost 
> at the moment. 
> Any help would do! 
> Thanks! 
>

Please don't send an html message;  this is a text mailing list, and
your text is hopelessly mangled.

For the benefit of others, I reformatted the code and enclose it here,
with tabs turned into 4 spaces.

months = 'January, February, March, April, May, June, July, August,
September, October, November, December'
daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'
#shorterMonths = 'February, April, June, September, Novmeber'
#longerMonths = 'January, March, May, July, August, October, December'
month = raw_input('Enter the month: ')
day = raw_input('Enter the day: ')
for x in month:
print "x = ", x
whichMonth = months.index(x)
monthNumber = daysPerMonth[whichMonth]
dayYear.append(monthNumber)

is this your first assignment?  Have you worked in any other programming
language before learning Python? Are you working with CPython 2.7 ?

Most of this code makes no sense to me at all.  Why isn't months a list
of strings?  Why isn't daysPerMonth a list of ints?  (I'm assuming that
shorterMonths and longerMonths are vestigial code.  If not, the two
spellings for November would surely cause troubles.

Why do you define day as a string, and not an int?

And why is the loop looping through the characters in the specified month?

Have you tried to describe in English how to solve the problem?



-- 

DaveA

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


Re: [Tutor] Sudoku

2012-09-24 Thread Dwight Hutto
Dwight,

Please stop responding to Mark.   His behaviour is typical schoolyard
bully, meaning he's saying things precisely because he gets a reaction
from you.  He probably doesn't even realise that he's doing it
consciously, but either way the best way to deal with such behaviour
is to stop giving such a person what they want, e.g. the reaction.
So, please just **stop responding** to any of his posts

I respond, to let him know that he just thinks I don't add context,
but lacks the ability to cheeck, that I do try to include context, but
in these question answer sessions, you should be following, the
conversation, which should put everything into context.



.  He'll soon
grow bored and move on.  If you had kept out of the conversation when
I'd originally replied to him then I'd have been able to take him to
task for his childish behaviour.   As it stands now unfortunately,
Myles' thread has become a wasteland of exchanges between yourself and
him.   Again: Please just stop responding to him.

Well, It's an argument, and I won't let him win. I could stop
responding, but then he would think he had won, and do it to someone
else.

He's wrong. He took one response out of context, and assumed that is
what I do, when usually it's just I followed the conversation for
real, and if he had, then he would know the context in which a certain
comment was made.

Thank you sincerely,

Walter Prins

On Mon, Sep 24, 2012 at 3:16 PM, Mark Lawrence  wrote:
> On 24/09/2012 17:52, Walter Prins wrote:
>>
>> Mark,
>>
>> On 23 September 2012 22:53, Mark Lawrence  wrote:

 Is the personal sniping really necessary?  (That's a rhetorical
 question, just to be clear.)

>>>
>>> Well if Dwight insists on replying to something without quoting the
>>> context
>>> so the rest of us haven't the faintest idea what he's talking about what
>>> are
>>> we meant to do?  Sadly my mind reading capabilities are quite low, I
>>> don't
>>> know about that for anyone else.
>>
>>
>> Well then tell him how to do it properly and/or provide a better
>> answer without the personal invective.  No one expects you to read
>> minds obviously, but the personal attacks and sarcasm are really way
>> out of line.  I can only hang my head in shame at what Myles must be
>> thinking of all this.  So childish.
>>
>> Walter

He only has one conversation to prove his point on, and I made the
point of telling him I was following a short conversation(at the
time), and therefore needed no context at the time, because the OP is
following the thread for the answer, and knows the context.

Walter's point of entry into the thread is of no concern to me,
because the OP is following the conversation. If Walter wants to know
the context, read the every post just like the OP would, because
that's who I'm responding to, not Walter.

> Dwight Hutto refers to my family as pigs and you have a go at

And when did I do that, please point out where I said that about your family.

> downright bloody check.  We're here to teach Python.  If he's too thick to
> understand context he can search the web for the word or resort to a
> dictionary.

If you're too thick to understand that sometimes it's an offhand
remark to JUST the OP, then you don't understand the context of a
tutor session in which one person asks a question, and gets responses.

You also seem to have missed lots of other conversations, where my
replies are in line.

You want an argument, and in this case you lose, because you couldn't
understand the context of my remark, because you think that every time
I respond it's without inline responses.

You don't know enough about me to say I always quote out of context,
and I can provide the evidence that I do.



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Aija Thompson

Hi,
Yeah this is my first assignment and I've never worked on anything programming 
before.
I am working in Python 2.7
The shorter and longer months thing is just a not to myself, that is why it has 
the hash tag before he sentence.
But my initial plan was to make a string of months and a string of the number 
of days in those months and have them compare to each other. So it would go 
through a loop and if you typed in February it would look through the list of 
numbers and see that January comes before and has 31 days and would add the 
number of days in February it has been. For instance 22. And it would add 22 to 
31 to come up with how many days it has been this year so far.  So I've been 
trying to make that work some way but I have so far been pretty unsuccesful. 
Does the way I'm even thinking about making the loop make sense?
Thanks!

> Date: Mon, 24 Sep 2012 16:48:56 -0400
> From: d...@davea.name
> To: aijathomp...@hotmail.com
> CC: tutor@python.org
> Subject: Re: [Tutor] Python Assignment Question
> 
> On 09/24/2012 03:20 PM, Aija Thompson wrote:
> > Hi! 
> > I've been working on this question for a long time and for some reason it's 
> > just not clicking. 
> > I'm not sure if my loop for the question is the right one, or if I'm even 
> > on the right track.
> > We're supposed to make a program that counts the number of days into the 
> > year it is if you input a date. Not including leap years. 
> > This is what I have so far:
> > months = 'January, February, March, April, May, June, July, August, 
> > September, October, November, December'daysPerMonth = '31, 28, 31, 30, 31, 
> > 30, 31, 31, 30, 31, 30, 31' #shorterMonths = 
> > 'February, April, June, September, Novmeber'#longerMonths = 'January, 
> > March, May, July, August, October, December'
> > month = raw_input('Enter the month: ')day = raw_input('Enter the day: ')
> > for x in month:whichMonth = months.index(x)monthNumber = 
> > daysPerMonth[whichMonth]dayYear.append(monthNumber)
> > I was hoping to make a loop that would check which month it is and compare 
> > it to the second list I made with the number of days in that month. I don't 
> > know if I've made that clear to the program or not. Either way, I feel 
> > pretty lost at the moment. 
> > Any help would do! 
> > Thanks!   
> >
> 
> Please don't send an html message;  this is a text mailing list, and
> your text is hopelessly mangled.
> 
> For the benefit of others, I reformatted the code and enclose it here,
> with tabs turned into 4 spaces.
> 
> months = 'January, February, March, April, May, June, July, August,
> September, October, November, December'
> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'
> #shorterMonths = 'February, April, June, September, Novmeber'
> #longerMonths = 'January, March, May, July, August, October, December'
> month = raw_input('Enter the month: ')
> day = raw_input('Enter the day: ')
> for x in month:
> print "x = ", x
> whichMonth = months.index(x)
> monthNumber = daysPerMonth[whichMonth]
> dayYear.append(monthNumber)
> 
> is this your first assignment?  Have you worked in any other programming
> language before learning Python? Are you working with CPython 2.7 ?
> 
> Most of this code makes no sense to me at all.  Why isn't months a list
> of strings?  Why isn't daysPerMonth a list of ints?  (I'm assuming that
> shorterMonths and longerMonths are vestigial code.  If not, the two
> spellings for November would surely cause troubles.
> 
> Why do you define day as a string, and not an int?
> 
> And why is the loop looping through the characters in the specified month?
> 
> Have you tried to describe in English how to solve the problem?
> 
> 
> 
> -- 
> 
> DaveA
> 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assignment Question

2012-09-24 Thread Dave Angel
On 09/24/2012 04:56 PM, Aija Thompson wrote:
> 
> Hi,

By top-posting, you lose all the context.  The convention is to quote
those parts of the previous messages necessary to understand the
context, and then add your own remarks immediately after the appropriate
parts.


> Yeah this is my first assignment and I've never worked on anything 
> programming before.
> I am working in Python 2.7
> The shorter and longer months thing is just a not to myself, that is why it 
> has the hash tag before he sentence.
> But my initial plan was to make a string of months

Fine.  Have you played with it?  Try something like this to get an idea
what you have:

months = 'January, February, March, April, May, June, July, August,
September, October, November, December'
for amonth in months:
print amonth

See what's wrong?  Can you imagine what the difference might be if it
were a list of strings?

Once you get that, try the same kind of experimenting with the other
anomalies I pointed out.

I expect you haven't gotten a feeling for what all the various native
types are good for, list, string, int, float.

Are you also familiar with what int() does to a string?  What def
functions are?

I'm sorry if i seem harsh, but this seems like a tough first assignment.
 You have to use a dozen concepts you apparently haven't wielded before.
 Weren't there exercises in the chapters you've been studying?  Did you
try every one of them?

I'm actually somewhat envious of the way people get to try out computer
programs today.  That wasn't an option when I started.  So take
advantage of it.  Write tiny programs and see whether they work, then
figure out why not and fix them.


 and a string of the number of days in those months and have them
compare to each other. So it would go through a loop and if you typed in
February it would look through the list of numbers and see that January
comes before and has 31 days and would add the number of days in
February it has been. For instance 22. And it would add 22 to 31 to come
up with how many days it has been this year so far.  So I've been trying
to make that work some way but I have so far been pretty unsuccesful.
Does the way I'm even thinking about making the loop make sense?
> Thanks!
> 



-- 

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Gregory Lund
>> but now get a   "  x = zipfile.Zipfile(item,'r')
>> AttributeError: 'module' object has no attribute 'Zipfile' "
>>
>> error
>>
>> gr, this is going to send me to the funny farm!
>>
>> greg
>>
> One way to avoid the "funny farm" is to learn to use the tools that
> Python provides, built-in.  As soon as you get an error like that one,
> add a print statement immediately before the one in error, and find the
> type and attributes of the object that supposedly doesn't have the
> attribute.  For example, you could have added a dir(zipfile), and then
> studied the one that seems to be the same as the one you tried to use.
> Presumably you would have quickly discovered what Oscar pointed out.
>
Thank you, I have printed and added to my Python quick hints.

> We all make typos, the difference is in how quickly we find and fix
> them.  Use the tools.
>
must admit, I didn't notice the typo.
> --
Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Gregory Lund
>
> Capital F. ZipFile not Zipfile.
>
Keyboard - Forehead - SCHMACK.
(and hand/forehead smack.)

DOH!

Thank you.

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 22:15, Gregory Lund  wrote:

> >> but now get a   "  x = zipfile.Zipfile(item,'r')
> >> AttributeError: 'module' object has no attribute 'Zipfile' "
> >>
> >> error
> >>
> >> gr, this is going to send me to the funny farm!
> >>
> >> greg
> >>
> > One way to avoid the "funny farm" is to learn to use the tools that
> > Python provides, built-in.  As soon as you get an error like that one,
> > add a print statement immediately before the one in error, and find the
> > type and attributes of the object that supposedly doesn't have the
> > attribute.  For example, you could have added a dir(zipfile), and then
> > studied the one that seems to be the same as the one you tried to use.
> > Presumably you would have quickly discovered what Oscar pointed out.
> >
> Thank you, I have printed and added to my Python quick hints.
>
> > We all make typos, the difference is in how quickly we find and fix
> > them.  Use the tools.
> >
> must admit, I didn't notice the typo.
>

No but Python did when it ran your code and it tried to tell you. The trick
is to read the error message, see what line of code it occurs at and then
look very closely at that line of code and the surrounding lines of code.
The first thing to check for is a typo.

The error message that Python gives may seem cryptic but it's actually very
informative if you know how to read it. For this reason it's also more
helpful to show the *verbatim* error message when posting to this (or
other) lists.

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


Re: [Tutor] running program in terminal

2012-09-24 Thread Matt Hite
On Mon, Sep 24, 2012 at 9:41 AM, Benjamin Fishbein
 wrote:
> Hello. I can run programs in IDLE but when I try to do it in a terminal or 
> with textwrangler, it usually just logs out and says it's completed, but the 
> program hasn't been run. This is particularly so when the program uses 
> urllib. I'm using OS X.

Try adding this to the end:

x = raw_input("Waiting for you to hit enter...")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OT: Netiquette

2012-09-24 Thread Prasad, Ramit
Note: attributions might be a bit off due to the way this was sent. 

Dwight Hutto wrote:
> 
> Dwight,
> 
> Please stop responding to Mark.   His behaviour is typical schoolyard
> bully, meaning he's saying things precisely because he gets a reaction
> from you.  He probably doesn't even realise that he's doing it
> consciously, but either way the best way to deal with such behaviour
> is to stop giving such a person what they want, e.g. the reaction.
> So, please just **stop responding** to any of his posts
> 
> I respond, to let him know that he just thinks I don't add context,
> but lacks the ability to cheeck, that I do try to include context, but
> in these question answer sessions, you should be following, the
> conversation, which should put everything into context.

To be fair, I do not think Mark is chastising you for context anywhere
that you actually provide context; only when it is missing. I do agree 
it was unnecessary to remark on your use of context in one thread.

> .  He'll soon
> grow bored and move on.  If you had kept out of the conversation when
> I'd originally replied to him then I'd have been able to take him to
> task for his childish behaviour.   As it stands now unfortunately,
> Myles' thread has become a wasteland of exchanges between yourself and
> him.   Again: Please just stop responding to him.
> 
> Well, It's an argument, and I won't let him win. I could stop
> responding, but then he would think he had won, and do it to someone
> else.

Hmm, arguing on the internet. Reminds me of:
http://www.systemcomic.com/2011/08/03/so-youre-mad-about-something-on-the-internet/
 
and http://xkcd.com/386/ 

> 
> He's wrong. He took one response out of context, and assumed that is
> what I do, when usually it's just I followed the conversation for
> real, and if he had, then he would know the context in which a certain
> comment was made.

You have forgotten context more often than "one response". I am not 
sure what you mean by "I followed the conversation for real..."

> 
> Thank you sincerely,
> 
> Walter Prins
> 
> On Mon, Sep 24, 2012 at 3:16 PM, Mark Lawrence 
> wrote:
> > On 24/09/2012 17:52, Walter Prins wrote:
> >>
> >> Mark,
> >>
> >> On 23 September 2012 22:53, Mark Lawrence  wrote:
> 
>  Is the personal sniping really necessary?  (That's a rhetorical
>  question, just to be clear.)
> 
> >>>
> >>> Well if Dwight insists on replying to something without quoting the
> >>> context
> >>> so the rest of us haven't the faintest idea what he's talking about what
> >>> are
> >>> we meant to do?  Sadly my mind reading capabilities are quite low, I
> >>> don't
> >>> know about that for anyone else.
> >>
> >>
> >> Well then tell him how to do it properly and/or provide a better
> >> answer without the personal invective.  No one expects you to read
> >> minds obviously, but the personal attacks and sarcasm are really way
> >> out of line.  I can only hang my head in shame at what Myles must be
> >> thinking of all this.  So childish.

Agreed. Wait, who is Myles? The OP?

> >>
> >> Walter
> 
> He only has one conversation to prove his point on, and I made the
> point of telling him I was following a short conversation(at the
> time), and therefore needed no context at the time, because the OP is
> following the thread for the answer, and knows the context.
> 
> Walter's point of entry into the thread is of no concern to me,
> because the OP is following the conversation. If Walter wants to know
> the context, read the every post just like the OP would, because
> that's who I'm responding to, not Walter.
> 
> > Dwight Hutto refers to my family as pigs and you have a go at
> 
> And when did I do that, please point out where I said that about your family.

"""> window I've just spotted a squadron of low flying pigs.

A family reunion no doubt. Maybe if you could pay attention instead of
picking sides you would understand the argument, and comment.

From: http://thread.gmane.org/gmane.comp.python.tutor/77951/focus=77955

> 
> > downright bloody check.  We're here to teach Python.  If he's too thick to
> > understand context he can search the web for the word or resort to a
> > dictionary.
> 
> If you're too thick to understand that sometimes it's an offhand
> remark to JUST the OP, then you don't understand the context of a
> tutor session in which one person asks a question, and gets responses.

True, but that is not really helpful to other people who may be reading
and curious or able to offer a correction/comment. Not to mention
anyone in need of future help. Though I have noted that you do attempt
to place context sometimes and I appreciate that. 

> 
> You also seem to have missed lots of other conversations, where my
> replies are in line.
> 
> You want an argument, and in this case you lose, because you couldn't
> understand the context of my remark, because you think that every time
> I respond it's without inline responses.
> 
> You don't know enough about me to say I 

Re: [Tutor] running program in terminal

2012-09-24 Thread Alan Gauld

On 24/09/12 17:41, Benjamin Fishbein wrote:

Hello. I can run programs in IDLE but when I try to do it in a terminal or with 
textwrangler, it usually just logs out and says it's completed, but the program 
hasn't been run. This is particularly so when the program uses urllib. I'm 
using OS X.

logout

[Process completed]

That's what it prints.
Any idea what to do?



Can you start up a terminal window then try to run your program and 
finally paste the whole session into a mail and post it here?


That should help.
If your program is complex try a simple one like:

print ('Hello world')
input('Hit enter to quit...')



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] BMI Question

2012-09-24 Thread Alan Gauld

On 24/09/12 20:13, Aija Thompson wrote:

Hi!

So I've been working on this question for hours! And Python keeps giving
me an error saying that my syntax for BMI is wrong. I really can't
understand why.



So send us the full error text not a summary.

If Python reports a syntax its usually recorded at the point immediately 
after the error so you may have to look at the line before.



So this is what I have so far:

w = raw_input('Please give your weight in lbs: ')
h = raw_input('Now your height in feet and inches: ')
h. split("'")
ft, inches = h. split("'")
h_sum = float(12*int(ft)) + (int(inches.strip('"'))


count the parens in the last expression...


BMI = float(703*w)/float(h_sum*h_sum)
print 'Your BMI is: ', BMI




HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] BMI Question

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:13 PM, Alan Gauld  wrote:
> On 24/09/12 20:13, Aija Thompson wrote:
>>
>> Hi!
>>
>> So I've been working on this question for hours! And Python keeps giving
>> me an error saying that my syntax for BMI is wrong. I really can't
>> understand why.
>
>
I'd suggest an editor, or editor option that highlights the end of
certain code separators like brackets/parenthesis

>
> So send us the full error text not a summary.
>
> If Python reports a syntax its usually recorded at the point immediately
> after the error so you may have to look at the line before.
>
>> So this is what I have so far:
>>
>> w = raw_input('Please give your weight in lbs: ')
>> h = raw_input('Now your height in feet and inches: ')
>> h. split("'")
>> ft, inches = h. split("'")
>> h_sum = float(12*int(ft)) + (int(inches.strip('"'))
>
>
> count the parens in the last expression...
>
>> BMI = float(703*w)/float(h_sum*h_sum)
>> print 'Your BMI is: ', BMI
>
>
>
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BMI Question

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:25 PM, Dwight Hutto  wrote:
> On Mon, Sep 24, 2012 at 7:13 PM, Alan Gauld  wrote:
>> On 24/09/12 20:13, Aija Thompson wrote:
>>>
>>> Hi!
>>>
>>> So I've been working on this question for hours! And Python keeps giving
>>> me an error saying that my syntax for BMI is wrong. I really can't
>>> understand why.
>>
>>
> I'd suggest an editor, or editor option that highlights the end of
> certain code separators like brackets/parenthesis
>
>>
>> So send us the full error text not a summary.
>>
>> If Python reports a syntax its usually recorded at the point immediately
>> after the error so you may have to look at the line before.
>>
>>> So this is what I have so far:
>>>
>>> w = raw_input('Please give your weight in lbs: ')
>>> h = raw_input('Now your height in feet and inches: ')
>>> h. split("'")
>>> ft, inches = h. split("'")
>>> h_sum = float(12*int(ft)) + (int(inches.strip('"'))
>>
>>
>> count the parens in the last expression...
>>
Proper netiquette suggests I place this here:

I'd suggest an editor, or editor option that highlights the end of
certain code separators like brackets/parenthesis so you can see the
in depth parameters placed into code.

>>> BMI = float(703*w)/float(h_sum*h_sum)
>>> print 'Your BMI is: ', BMI

>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running program in terminal

2012-09-24 Thread Benjamin Fishbein
> 
> Can you start up a terminal window then try to run your program and finally 
> paste the whole session into a mail and post it here?
> 
> That should help.
> If your program is complex try a simple one like:
> 
> print ('Hello world')
> input('Hit enter to quit...')

Last login: Mon Sep 24 18:27:48 on ttys000
Benjamins-MacBook-Air:~ bfishbein$ cd '/Users/bfishbein/Documents/Python in 
Use/' && '/usr/local/bin/pythonw'  '/Users/bfishbein/Documents/Python in 
Use/BB.py'  && echo Exit status: $? && exit 1
put in the text input  

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>http://www.w3.org/1999/xhtml"; xmlns:fb="http://ogp.me/ns/fb#";> 
Textbooks.com - Your Search Results for Buyback___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Gregory Lund
> No but Python did when it ran your code and it tried to tell you. The trick
> is to read the error message, see what line of code it occurs at and then
> look very closely at that line of code and the surrounding lines of code.
> The first thing to check for is a typo.

To be honest, I did check for typos, a misplaced period, etc., but
didn't notice it, I even compared it with the similar line above, but
didn't notice the 'F'.
(Truth Hurts)
>
> The error message that Python gives may seem cryptic but it's actually very
> informative if you know how to read it. For this reason it's also more
> helpful to show the *verbatim* error message when posting to this (or other)
> lists.
>
I will show the verbatim error message from now on, thank you for suggesting it!
, speaking of which:

This is my code, as modified based on all the great help thus far.

(again, I need a stand alone .py file for my purposes and need to use
Python 2.6 because it's the version that works with my GIS application
(Esri's ArcGIS).


import os, os.path, zipfile, arcpy

in_Zip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18
Lab_2.zip'

outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"

z = zipfile.ZipFile(in_Zip,'r')

z.extractall(outDir)

zipContents = z.namelist()
print zipContents
z.close()

for item in zipContents:
if item.endswith('.zip'):
x = zipfile.ZipFile(item,'r')
x.extractall()
x.close()

for the record, I print  'zipContents' to help me figure out how to
'get into' the first folder of the extracted zip which is never a zip
folder, but a non-zipped folder, that holds (usually) 1 or more .zip
files (folders that are zipped)

This is the way I receive the data from the Learning Management System
LMS). The initial zip (2012-09-18 Lab_2.zip) is created by the LMS,
and actually the internal folders (aforker, allisw99, etc.) are also
created by the LMS (its' how the LMS sorts the individual student
folders/upload using their user name.

my results and error of the above code is listed below.

IDLE 2.6.5
>>>  RESTART 
>>>
['Lab_2/aforker/', 'Lab_2/aforker/aforker_Lab2.zip',
'Lab_2/allisw99/', 'Lab_2/allisw99/allisw99_Lab2.zip',
'Lab_2/allisw99/allisw99_Lab2_Bonus.pdf', 'Lab_2/allisw992/',
'Lab_2/allisw992/allisw99_Lab2_Bonus.pdf', 'Lab_2/btaylor7/',
'Lab_2/btaylor7/2nd_btaylor7_Lab2.zip',
'Lab_2/btaylor7/btaylor7_Lab2.zip', 'Lab_2/']

Traceback (most recent call last):
  File 
"D:/D_Drive_Documents/Scripts/Unzip_a_zip_of_zips/Scripts/unzip_a_zip_of_zips_rewrite_shortest_of_the_shorts2.py",
line 18, in 
x = zipfile.ZipFile(item,'r')
  File "C:\Python26\ArcGIS10.0\lib\zipfile.py", line 683, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 2] No such file or directory: 'Lab_2/aforker/aforker_Lab2.zip'
>>>

Near as I can tell, I got rid of the permissions error, the ZipFile
error with the missing capital 'F'
Now I need to 'get into' the non zipped folder of each student and
unzip any and all zips that are inside of it.

Thoughts?
Thanks again Oscar and Dave for sticking with me and not throwing in
the towel on my rookie errors!

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


Re: [Tutor] running program in terminal

2012-09-24 Thread Alan Gauld

On 25/09/12 00:31, Benjamin Fishbein wrote:


Last login: Mon Sep 24 18:27:48 on ttys000
Benjamins-MacBook-Air:~ bfishbein$ cd
'/Users/bfishbein/Documents/Python in Use/' &&
'/usr/local/bin/pythonw'  '/Users/bfishbein/Documents/Python in
Use/BB.py'  && echo Exit status: $? && exit 1


When debugging simplify the code.
In this case break it into individual commands so you can see the effect 
of each one and see where the errors are coming from.


However


put in the text input


,,, snip ,,,


href='http://www.textbooks.com/apple-touch-icon.png' />

When you say it 'stops' what exactly do you mean?
The above output suggests that far from stopping
the program terminates successfully (exit status 0).


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Oscar Benjamin
On 25 September 2012 00:33, Gregory Lund  wrote:
>
> z.extractall(outDir)
>
> zipContents = z.namelist()
> print zipContents
> z.close()
>
> for item in zipContents:
> if item.endswith('.zip'):
> x = zipfile.ZipFile(item,'r')
> x.extractall()
> x.close()
>
> Traceback (most recent call last):
>   File
> "D:/D_Drive_Documents/Scripts/Unzip_a_zip_of_zips/Scripts/unzip_a_zip_of_zips_rewrite_shortest_of_the_shorts2.py",
> line 18, in 
> x = zipfile.ZipFile(item,'r')
>   File "C:\Python26\ArcGIS10.0\lib\zipfile.py", line 683, in __init__
> self.fp = open(file, modeDict[mode])
> IOError: [Errno 2] No such file or directory:
> 'Lab_2/aforker/aforker_Lab2.zip'
> >>>
>
> Near as I can tell, I got rid of the permissions error, the ZipFile
> error with the missing capital 'F'
> Now I need to 'get into' the non zipped folder of each student and
> unzip any and all zips that are inside of it.
>

The error message says 'No such file or directory'. That means that when
Python tries to open a file with the name you gave it can't find a file
that has that name. In this case I suspect the problem is that you need to
give the full path to each file i.e. instead of
  'Lab_2/aforker/aforker_Lab2.zip'
you need to give
 
'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\Lab_2\aforker\aforker_Lab2.zip'

You can create the full path with:

import os.path   # Put this at the top of your file

for item in zipContents:
  if item.endswith('.zip'):
  # Combine the base folder name with the subpath to the zip file
  fullpath = os.path.join(outDir, item)
  x = zipfile.ZipFile(fullpath,'r')

I just googled to find you a page explaining absolute paths and, by chance,
came up with this from the ArcGIS documentation:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Pathnames%20explained%3A%20Absolute%2C%20relative%2C%20UNC%2C%20and%20URL

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-24 Thread Gregory Lund
>> Near as I can tell, I got rid of the permissions error, the ZipFile
>> error with the missing capital 'F'
>> Now I need to 'get into' the non zipped folder of each student and
>> unzip any and all zips that are inside of it.
>
>
> The error message says 'No such file or directory'. That means that when
> Python tries to open a file with the name you gave it can't find a file that
> has that name. In this case I suspect the problem is that you need to give
> the full path to each file i.e. instead of
>   'Lab_2/aforker/aforker_Lab2.zip'

full code is now:


import os, os.path, zipfile, arcpy

in_Zip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18
Lab_2.zip'

outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"

z = zipfile.ZipFile(in_Zip,'r')

z.extractall(outDir)

zipContents = z.namelist()
print zipContents
z.close()

for item in zipContents:
if item.endswith('.zip'):
# Combine the base folder name with the subpath to the zip file
fullpath = os.path.join(outDir, item)
x = zipfile.ZipFile(fullpath,'a')
x.extractall()
x.close()

NO errors! yea!
But, it's (I'm) still just extracting the first zip, not the zipfiles
within the Lab_2\aforker, Lab_2\allisw99 folders.

however, I used my brain (no comments!) and figured out that while
it's not extracting the info to the folders I want (the Lab_2\aforker,
Lab_2\allisw99 etc. folder, it's extracting them to the location in
which my script is stored.
I kept looking at it thinking 'OK, it didn't come up with an error,
but it's 'not' extracting, but it should be then I realized that I
didn't specify the folder to which I want it extracted.
Ta-da, that's why it's going back to where the script is stored.

So...
I tried to use:
x.extractall(fullpath) but that of course gave me errors because
'fullpath' is the path of the file.
I need to figure out how to just list the respective Lab_2\aforker,
Lab_2\allisw99 folders.

Thus far, I have not had any luck.
Does python have a way to go back to the relative folder where the zip
is located?

> I just googled to find you a page explaining absolute paths and, by chance,
> came up with this from the ArcGIS documentation:
> http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Pathnames%20explained%3A%20Absolute%2C%20relative%2C%20UNC%2C%20and%20URL

Good find, It's like pulling teeth to explain paths/directories to my students.
The relative vs. absolute paths is one of their first obstacles to
learning, yet really it's a simple check box in ArcGIS that is NOT a
default, and resets each night in the computer lab.

I am going to use that link you provided, tomorrow, the first day of GIS311!

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