[Tutor] Hey.need help on time

2012-09-06 Thread Keitaro Kaoru
been trying to change this so it wont use my server time. but my
actual time here in the us.EST. havent been able to figure it out

def sstime(user, body, m):
os.environ['TZ'] = 'US/Eastern'
tstr1 = time.strftime("%a, %b-%d-%Y", time.tzset())
tstr2 = time.strftime("%I:%M:%S %p", time.tzset())
tstr3 = time.strftime("%Z", time.tzset())
return Html("Today is %s and The current time is
%s (%s)" % (tstr1, tstr2, tstr3))

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


Re: [Tutor] Formatting questions regarding datetime.isoformat()

2012-09-06 Thread eryksun
On Wed, Sep 5, 2012 at 11:00 PM, staticsafe  wrote:
>
> In [68]: showinfo['RFC3339']
> Out[68]: '2012-09-10T21:00:00-4:00'

You can parse the ISO format using the dateutil module:

http://labix.org/python-dateutil

>>> from dateutil.parser import parse
>>> show_time = parse('2012-09-10T21:00:00-4:00')

This produces a time-zone aware datetime object. You can pass its
tzinfo to datetime.now() to get the current time as an aware datetime
object:

>>> now = datetime.now(show_time.tzinfo)

Or you could use datetime.now(dateutil.tz.tzutc()) for a UTC tzinfo.
It doesn't matter if you're only interested in the timedelta.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Formatting questions regarding datetime.isoformat()

2012-09-06 Thread Peter Otten
staticsafe wrote:

> Hello,
> 
> I am running Python 2.6.6 on a Debian Squeeze system. I am using two
> modules in this bit of code - datetime and python-tvrage (available on
> pypy here: http://pypi.python.org/pypi/python-tvrage/).
> 
> My goal is to find the time remaining until a certain show airs. Here is
> some code I have written so far:
> 
> #!/usr/bin/env python
> from tvrage import quickinfo
> from datetime import tzinfo, timedelta, datetime
> 
> showinfo = quickinfo.fetch("Warehouse 13")
> nextairdate = showinfo['RFC3369']
> now = datetime.now().isoformat()
> 
> Now for my question/problem.
> 
> In [68]: showinfo['RFC3339']
> Out[68]: '2012-09-10T21:00:00-4:00'
> 
> In [72]: datetime.now().isoformat()
> Out[72]: '2012-09-05T22:47:46.061688'
> 
> isoformat() is in a different format than the value returned by the API.
> My question is how would one format both values so that I can perform a
> timedelta on them as is the purpose of my code?
> 
> I hope I have provided the right amount of detail for my question.

After some trial and error:

import dateutil.parser # python-dateutil
import pytz # python-tz
import datetime

show_start = dateutil.parser.parse("2012-09-10T21:00:00-0400")
now = datetime.datetime.now(pytz.timezone("EST"))

print "show starts: ", show_start
print "current time:", now
print "days to go:  ", show_start - now

(Caveat: I'm using Python 2.7)

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


Re: [Tutor] Hey.need help on time

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 3:21 AM, Keitaro Kaoru  wrote:
> been trying to change this so it wont use my server time. but my
> actual time here in the us.EST. havent been able to figure it out
>
> def sstime(user, body, m):
> os.environ['TZ'] = 'US/Eastern'

Now just call time.tzset(), and it should work.

> tstr1 = time.strftime("%a, %b-%d-%Y", time.tzset())

I don't know what you're doing here. strftime() uses localtime() if
you don't provide a time tuple. time.tzset() just returns None.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Xmpp Received Message

2012-09-06 Thread Ahmet Can KEPENEK
I wrote application with xmpp. It  sending message from gtalk. I want to
print received message. How can i do? My application short code as follows.

def process_message():
client = xmpp.Client('gmail.com')
client.connect( server=('talk.google.com',5223) )

client.auth(user,passwd, 'botty')

to = raw_input("to: ");
if client:
message = raw_input("message: ")
client.send( xmpp.Message( to,message ) )


if __name__ == "__main__":
user = raw_input("User: ")
passwd = getpass.getpass("Pass: ")
process_message()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Xmpp Received Message

2012-09-06 Thread Alan Gauld

On 06/09/12 08:59, Ahmet Can KEPENEK wrote:

I wrote application with xmpp. It  sending message from gtalk. I want to
print received message. How can i do?


This mailing list is really for people learning Python and its standard 
library. Your question is mainly about xmpp which I assume is some kind 
of Google API? Whether you get an answer will depend on how lucky you 
are as to whether anyone here has used xmpp.


You will likely get a better response on an xmpp forum or even on the 
main Python mailing list/newsgroup: comp.lang.python


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


[Tutor] math description

2012-09-06 Thread damjan kuzmic
Hello,
i would like to know how to write a formula that in excell looks like this:

A / EXP(-LN(2) * t)

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


[Tutor] Help

2012-09-06 Thread Ian o donovan
Hey, I am writing this to you because I want to know could you help.
My school is doing enterprise and I want to enter. I really want to
make a program that will clean up your desktop E.G put files you
haven't used for a while into a folder and delete your trash they are
just a few ideas. I am trying to learn programming but I live in
Ireland and where I live they is not much access to courses so I have
to wait till college to learn programming. I have tried to learn some
of python through on-line tutorials but find it hard So what I am
asking is
could you help me make a program if not I understand as I can imagine
ye are very busy people.
Thanks for reading this.
Ian Lawlor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Doing the same thing twice. Works first time but not the second.

2012-09-06 Thread Matthew Love
This error is confusing me. I am wondering if anyone can help me out.

Using W7 64 Ultimate
Using Python 3.1.1


This is the relevant part of the program.


class Player(object):

def __init__(self):
print("Player created.")

def inventory(self):
self.inventory = ["torch"]
return self.inventory

player = Player()

print("\nYour current inventory is", end= " ")
print(player.inventory())

print("\nYour current inventory is", end= " ")
print(player.inventory())


The first time the program prints the inventory correctly but when it
does the exact same thing again it throws up an error. I can't think
of a reason for why this happens.

This is the error:

Traceback (most recent call last):
  File "C:\Users\Matthew\Desktop\test.py", line 16, in 
print(player.inventory())
TypeError: 'list' object is not callable


Can anyone help me with this? I'd appreciate it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help

2012-09-06 Thread Jack Little
> Ok, I am somewhat new to python, and I am making a text-based RPG. I get a
> weird error with this code:
>
>
> #A Python text-RPG
> #A Jak Production
> #APOC
> global ammo
> global health
> global lives
> global exp
> global food
> ammo=55
> health = 100
> lives=10
> exp = 0
> food = 30
>
> def part1():
>    print "50 Days After The Outbreak:You are standing outside of the Empire
> State Building."
>    print "Vines, plants, dirt, and grime cover its once-regal surfaces.
> Huh."
>    print "I guess if 80% of the world is dead, more people are concerned
> about survival than sightseeing.God."
>    print "Generally,us survivors tend to band together. Mostly  it is for
> good. Not the bandits."
>    print "  Bandit:'Hey you! What you got in that bag?"
>    print "I recognized this Bandit as Sam Cabelo. He was the janitor at my
> office building. Not the nicest fellow."
>    answer = raw_input("Type 'show' or 'run away' then hit the 'Enter'
> button.")
>    if answer == "SHOW" or answer == "Show" or answer == "show":
>        print "Ahhh. Nice .45 you got there. And some food.Hand it over.(He
> says this like a threat, reinforced by that revolver in his hand"
>        answer2 = raw_input("Type either Hand it over or flee")
>        if answer2 == "HAND IT OVER" or answer2 == "Hand it over" or answer2
> == "hand it over":
>            print "Bandit: Good Job.. Go on now"
>            ammo=ammo-15
>            food=food-10
>            return answer3
>        if answer2 == "FLEE" or answer2 == "Flee" or answer2 == "flee":
>            print "He shot you"
>            lives=lives-1
>        else:
>            print "TYPE  SOMETHING CORRECTLY"
>            return part1
>
>    elif answer == "run away" or "Run Away" or "RUN AWAY":
>        print "He shot you... hee hee hee"
>        print "When the input comes up again, type a differet answer"
>    else:
>        print "You didn't type Show or run away."
>        part1()
>
> part1()
>
>
> Here is my error, if it helps
>
> Traceback (most recent call last):
>  File "C:\Users\Jack\Desktop\game2.py", line 45, in 
>    part1()
>  File "C:\Users\Jack\Desktop\game2.py", line 28, in part1
>    ammo=ammo-15
> UnboundLocalError: local variable 'ammo' referenced before assignment
>
>
> Thanks,
> Jack Little 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to get MAC address using Python at windows 7

2012-09-06 Thread šãñ
I need to find some way how i can get mac address of windows 7 in python..
-- 
**

[image: San's personal blog] 

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


Re: [Tutor] Formatting questions regarding datetime.isoformat()

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 3:50 AM, Dave Angel  wrote:
> On 09/06/2012 03:35 AM, eryksun wrote:
>> 
>> Or you could use datetime.now(dateutil.tz.tzutc()) for a UTC tzinfo.
>> It doesn't matter if you're only interested in the timedelta.
>
> Actually, it can matter.  Whenever possible, produce all times as UTC
> and do your manipulations (eg. difference) in that space.  With local
> time, there are times that don't exist and times that are ambiguous, one
> in the fall and one in the spring, due to setting the clock forward or back.
>
> i don't know for sure if it matters here, but I've found it's better to
> work that way.

These are aware datetime objects. See the datetime docs for supported
operations, case 3, timedelta = datetime1 - datetime2:

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


[Tutor] Python 2.7.3, Pygame, and LiveWires

2012-09-06 Thread Jason Fremouw
Hello,

My name is Jason Fremouw. I recently began a Structured Programming course
using Python as the tool with which we'll learn. The media packages listed
above come as add-ons in my text book but are not compatible with 2.7. Are
these now built into the latest build of Python or are they listed as
different downloads on Python.org?

Any help would be greatly appreciated!

Thank you.

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


[Tutor] Python

2012-09-06 Thread Andrew Rosen
I have a Windows Computer and I'm trying to make a shortcut on my desktop that 
will run a program, so I don't have to open up a New Window form Python Shell 
and use that to run the program. I can't figure out how to do it, can you help 
me?___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python 2.7.1

2012-09-06 Thread john
print "hello world" #this is just something to say





>>> /Users/jonathan/Documents/hello.py 
  File "", line 1
/Users/jonathan/Documents/hello.py 
^
SyntaxError: invalid syntax

what am i doing wrong?

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


[Tutor] how to print array without adding newline

2012-09-06 Thread vickistan
Hello: I am trying to output an array to another program that takes an array
as input, but the print statement adds a newline. If it were adding to each
individual element, I could solve it easily, but it is adding one at the end
of the array. Is there another way to print an array besides 

print arrayname

If it were a string, I have a whole host of options, but I need it to be
output as an array. Each element is a url. I call it from a browser, and it
works except for the added newline.

Here are the relevant lines:

=
/* code that connects to cloudfiles omitted */

containers = conn.get_all_containers()
i=0
print "Content-type: text/html\n\n";
wholelist=containers[0].list_objects()
random.shuffle(wholelist)
newlist=[]
try:
del wholelist[int(sys.argv[1]):]
while i < int(sys.argv[1]):
newlist.append("http://example.com/"+wholelist[i].rstrip())
i = i+1
except IndexError, e:
del newlist[5]
print newlist
==

The output I am seeing is as follows:

['http://example.com/wet-longhaireddachshund.jpg',
'http://example.com/dachshund2.jpg',
'http://example.com/dachshundingrass.jpg'] 

Any tips on better coding practices are welcome, but please don't beat me up

Thanks,
vickistan




--
View this message in context: 
http://python.6.n6.nabble.com/how-to-print-array-without-adding-newline-tp4985646.html
Sent from the Python - tutor mailing list archive at Nabble.com.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hey.need help on time

2012-09-06 Thread Ray Jones
On 09/06/2012 12:51 AM, eryksun wrote:
> On Thu, Sep 6, 2012 at 3:21 AM, Keitaro Kaoru  wrote:
>> been trying to change this so it wont use my server time. but my
>> actual time here in the us.EST. havent been able to figure it out
>>
>> def sstime(user, body, m):
>> os.environ['TZ'] = 'US/Eastern'
> Now just call time.tzset(), and it should work.
Why the additional step of calling time.tzset()? Once os.environ['TZ']
is set, I've found that time.localtime() responds to the new TZ without
anything extra. Is that a difference in versions (2.7.3 here)?


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


[Tutor] python wifi

2012-09-06 Thread Sales
Hello,
I'm trying to install python wifi using easy install. I have python27 and 
working on mac os. from a shell I'm running:

easy_install python_wifi-0.5.0-py2.5.egg

I also tried:

sudo easy_install python_wifi-0.5.0-py2.5.egg

I pasted the output error below. I'm not familiar with easy_install or python 
wifi. What am I doing wrong here? thanks!


Downloading 
http://pypi.python.org/packages/any/p/python-wifi/python_wifi-0.5.0-py2.5.egg#md5=d7995ad357387d3c2f8b13bcac5c4e20,
Processing python_wifi-0.5.0-py2.5.egg
Removing 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_wifi-0.5.0-py2.5.egg
Moving python_wifi-0.5.0-py2.5.egg to 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
python-wifi 0.5.0 is already the active version in easy-install.pth

Installed 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_wifi-0.5.0-py2.5.egg
Processing dependencies for python-wifi==0.5.0
Searching for python-wifi==0.5.0
Reading http://pypi.python.org/simple/python-wifi/
Reading http://pythonwifi.wikispot.org
Reading https://developer.berlios.de/projects/pythonwifi/
Reading http://www.romanofski.de/downloads/pywifi
No local packages or download links found for python-wifi==0.5.0
Best match: None
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install", 
line 8, in 
load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 1712, in main
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 1700, in with_ei_usage
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 1716, in 
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py",
 line 152, in setup
dist.run_commands()
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
 line 953, in run_commands
self.run_command(cmd)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
 line 972, in run_command
cmd_obj.run()
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 211, in run
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 422, in easy_install
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 478, in install_item
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 519, in process_distribution
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
 line 563, in resolve
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
 line 799, in best_match
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
 line 811, in obtain
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py",
 line 434, in easy_install
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/package_index.py",
 line 475, in fetch_distribution
AttributeError: 'NoneType' object has no attribute 'clone'


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


Re: [Tutor] math description

2012-09-06 Thread Mark Lawrence

On 29/08/2012 21:20, damjan kuzmic wrote:

Hello,
i would like to know how to write a formula that in excell looks like this:

A / EXP(-LN(2) * t)



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



Start here http://docs.python.org/tutorial/

--
Cheers.

Mark Lawrence.

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


[Tutor] apologies for any duplicate mails coming through

2012-09-06 Thread Alan Gauld
I've just been into the admin interface and flushed a heap of messages 
in the moderators queue. I hadn't logged in for a while and quite a 
stack had built up - mostly spam... :-(


Some were a few weeks old so apologies if some of them have already been 
seen and dealt with.


--
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] Help

2012-09-06 Thread Ray Jones
On 09/03/2012 07:39 AM, Jack Little wrote:
> > Ok, I am somewhat new to python, and I am making a text-based RPG. I get a
> > weird error with this code:
> >
> >
> > #A Python text-RPG
> > #A Jak Production
> > #APOC
> > global ammo
> > global health
> > global lives
> > global exp
> > global food
> > ammo=55
> > health = 100
> > lives=10
> > exp = 0
> > food = 30
> >
> > def part1():
> >print "50 Days After The Outbreak:You are standing outside of the Empire
> > State Building."
> >print "Vines, plants, dirt, and grime cover its once-regal surfaces.
> > Huh."
> >print "I guess if 80% of the world is dead, more people are concerned
> > about survival than sightseeing.God."
> >print "Generally,us survivors tend to band together. Mostly  it is for
> > good. Not the bandits."
> >print "  Bandit:'Hey you! What you got in that bag?"
> >print "I recognized this Bandit as Sam Cabelo. He was the janitor at my
> > office building. Not the nicest fellow."
> >answer = raw_input("Type 'show' or 'run away' then hit the 'Enter'
> > button.")
> >if answer == "SHOW" or answer == "Show" or answer == "show":
> >print "Ahhh. Nice .45 you got there. And some food.Hand it over.(He
> > says this like a threat, reinforced by that revolver in his hand"
> >answer2 = raw_input("Type either Hand it over or flee")
> >if answer2 == "HAND IT OVER" or answer2 == "Hand it over" or answer2
> > == "hand it over":
> >print "Bandit: Good Job.. Go on now"
> >ammo=ammo-15
> >  
I'll take a stab at it. You are using attempting to modify a global
variable within a procedure. Procedure variables are separate from
global variables. Global variables must be passed into a procedure using
something on the order of 'part1(ammo)', and then returned back from the
procedure with a 'return '


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


Re: [Tutor] Help

2012-09-06 Thread Dave Angel
On 09/03/2012 10:39 AM, Jack Little wrote:
>> Ok, I am somewhat new to python, and I am making a text-based RPG. I get a
>> weird error with this code:
>>
>>
>> #A Python text-RPG
>> #A Jak Production
>> #APOC
>> global ammo
>> global health
>> global lives
>> global exp
>> global food
>> ammo=55
>> health = 100
>> lives=10
>> exp = 0
>> food = 30
>>
>> def part1():
>> print "50 Days After The Outbreak:You are standing outside of the Empire
>> State Building."
>> print "Vines, plants, dirt, and grime cover its once-regal surfaces.
>> Huh."
>> print "I guess if 80% of the world is dead, more people are concerned
>> about survival than sightseeing.God."
>> print "Generally,us survivors tend to band together. Mostly  it is for
>> good. Not the bandits."
>> print "  Bandit:'Hey you! What you got in that bag?"
>> print "I recognized this Bandit as Sam Cabelo. He was the janitor at my
>> office building. Not the nicest fellow."
>> answer = raw_input("Type 'show' or 'run away' then hit the 'Enter'
>> button.")
>> if answer == "SHOW" or answer == "Show" or answer == "show":
>> print "Ahhh. Nice .45 you got there. And some food.Hand it over.(He
>> says this like a threat, reinforced by that revolver in his hand"
>> answer2 = raw_input("Type either Hand it over or flee")
>> if answer2 == "HAND IT OVER" or answer2 == "Hand it over" or answer2
>> == "hand it over":
>> print "Bandit: Good Job.. Go on now"
>> ammo=ammo-15
>> food=food-10
>> return answer3
>> if answer2 == "FLEE" or answer2 == "Flee" or answer2 == "flee":
>> print "He shot you"
>> lives=lives-1
>> else:
>> print "TYPE  SOMETHING CORRECTLY"
>> return part1
>>
>> elif answer == "run away" or "Run Away" or "RUN AWAY":
>> print "He shot you... hee hee hee"
>> print "When the input comes up again, type a differet answer"
>> else:
>> print "You didn't type Show or run away."
>> part1()
>>
>> part1()
>>
>>
>> Here is my error, if it helps
>>
>> Traceback (most recent call last):
>>   File "C:\Users\Jack\Desktop\game2.py", line 45, in 
>> part1()
>>   File "C:\Users\Jack\Desktop\game2.py", line 28, in part1
>> ammo=ammo-15
>> UnboundLocalError: local variable 'ammo' referenced before assignment
>>
>>
>> Thanks,
>> Jack Little 
>
>

Your global declarations are all at top-level scope, where they are
meaningless.  All variables defined there are global.  What you want for
ammo is a global declaration inside the function.  By convention, you
declare any globals at the top of the function, right after the def and
the doc-string.

You'll also need global declarations for food and lives, and perhaps
others I didn't notice.

Other things I notice:

You omitted the parentheses in one reference to part1.  So it doesn't
get called there.

You try to use those part1() calls as some form of looping construct. 
Instead you should use a while loop or similar.  That also will avoid
the problem you've got now where if a person types nonsense to the
second question, he ends up being asked the first question again.

Use lower() method on strings to avoid needing multiple comparisons:
if answer2.lower() == "flee":



-- 

DaveA

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


Re: [Tutor] math description

2012-09-06 Thread Alan Gauld

On 29/08/12 21:20, damjan kuzmic wrote:

Hello,
i would like to know how to write a formula that in excell looks like this:

A / EXP(-LN(2) * t)



Start by breaking it down from the inside out.

LN(2) is log(2) in Python, which is found in the math module so you need
import math too.

negation ( -LN() ) and multiplication are builtin (* t)

EXP() is exp(), also in the math module.

division is built in (although I'm not sure if Excel / is integer
or 'real' division, given the nature of the values I'll assume its real...

So the final expression should look like

import math
...
value = A/math.exp(-math.log(2) * t)

Which isn't too different to Excel.


--
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] Doing the same thing twice. Works first time but not the second.

2012-09-06 Thread eryksun
On Fri, Aug 17, 2012 at 4:11 PM, Matthew Love
 wrote:
> def inventory(self):
> self.inventory = ["torch"]
> return self.inventory

What is 'self.inventory' before you call inventory(), and what is it
afterwards? A quick fix would be to name the list "_inventory" and
return self._inventory.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 2.7.1

2012-09-06 Thread Dave Angel
On 08/20/2012 12:47 AM, john wrote:
> print "hello world" #this is just something to say
>
>
>
>
>
 /Users/jonathan/Documents/hello.py 
>   File "", line 1
> /Users/jonathan/Documents/hello.py 
> ^
> SyntaxError: invalid syntax
>
> what am i doing wrong?
>
>
>
it would help if you showed the actual content of hello.py.   Looks to
me like the first line looks like:
   

 /Users/jonathan/Documents/hello.py 

Comment that out, and see what happens.


-- 

DaveA

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


Re: [Tutor] help me decide

2012-09-06 Thread Matthew Ngaha
hey guys i just like to thank everyone for their input. Its really
helped me in deciding a lot of things. also @ Alan i think? as ive
started writing this mail it won;t let me look up previous senders but
thanks for your input. Also your field of work sounds very interesting
indeed. I can't dare to imagine the amount of hard work that got you
there.:) i only hope my dedication can take me half as far:)

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


Re: [Tutor] Doing the same thing twice. Works first time but not the second.

2012-09-06 Thread Alan Gauld

On 17/08/12 21:11, Matthew Love wrote:


class Player(object):

 def inventory(self):
 self.inventory = ["torch"]
 return self.inventory


Notice that you override the name inventory.
Initially self.inventory is the inventory() method.
But then you change self.inventory to be a list.

So the next time you call player.inventory() you are
trying to execute the list hence the error.

You need to change the name of the inventory attribute
to something like theInventory...

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] math description

2012-09-06 Thread Peter Otten
damjan kuzmic wrote:

> i would like to know how to write a formula that in excell looks like
> this:
> 
> A / EXP(-LN(2) * t)

>>> import math
>>> A = 1.23
>>> t = 4.56

Literally (math.log is the natural logarithm):
>>> A / math.exp(-math.log(2) * t)
29.013618196288864

However,
exp(-x) == 1 / exp(x)
and
exp(ln(a)*x) == a ** x
so you better spell it

>>> A * 2 ** t
29.013618196288864
 




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


Re: [Tutor] Python

2012-09-06 Thread Dave Angel
On 08/19/2012 04:42 PM, Andrew Rosen wrote:
> I have a Windows Computer and I'm trying to make a shortcut on my desktop 
> that will run a program, so I don't have to open up a New Window form Python 
> Shell and use that to run the program. I can't figure out how to do it, can 
> you help me?
>

This is a Windows question, not a Python one.  But I'll take a crack at
it, since I used to run Windows.

Use right-click on the desktop and choose  "create shortcut" from the
context menu.  Fill in the name of your script.  Give the shortcut a
useful name.

This assumes that you have the usual file associations stored in the
registry.  They are what tells the Windows system how to run a *.py file

-- 

DaveA

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


Re: [Tutor] Hey.need help on time

2012-09-06 Thread eryksun
On Thu, Sep 6, 2012 at 4:25 AM, Ray Jones  wrote:
>
> Why the additional step of calling time.tzset()? Once os.environ['TZ']
> is set, I've found that time.localtime() responds to the new TZ without
> anything extra. Is that a difference in versions (2.7.3 here)?

It shouldn't strictly be necessary using glibc. I checked the source.
glibc localtime calls __tz_convert() on each call, which calls
tzset_internal() to update the TZ setting. However, I don't think
that's guaranteed in all C runtimes. As the Python docs say,
"[c]hanging the TZ environment variable without calling tzset *may*
change the local timezone used by methods such as localtime, but this
behaviour should not be relied on."
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 2.7.1

2012-09-06 Thread Peter Otten
john wrote:

> print "hello world" #this is just something to say

 /Users/jonathan/Documents/hello.py
>   File "", line 1
> /Users/jonathan/Documents/hello.py
> ^
> SyntaxError: invalid syntax
> 
> what am i doing wrong?

The >>> prompt indicates that you have already started the interactive 
interpreter by typing

$ python

This is a great way to test Python statements interactively -- type and 
explore Python's response.

However, to run a script you have to provide the script name on the 
commandline

$ python /Users/jonathan/Documents/hello.py


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


Re: [Tutor] how to print array without adding newline

2012-09-06 Thread Dave Angel
On 08/18/2012 09:17 PM, vickistan wrote:
> Hello: I am trying to output an array to another program that takes an array
> as input, but the print statement adds a newline. If it were adding to each
> individual element, I could solve it easily, but it is adding one at the end
> of the array. Is there another way to print an array besides 
>
> print arrayname
>
> If it were a string, I have a whole host of options, but I need it to be
> output as an array. Each element is a url. I call it from a browser, and it
> works except for the added newline.
>
> Here are the relevant lines:
>
> =
> /* code that connects to cloudfiles omitted */
>
> containers = conn.get_all_containers()
> i=0
> print "Content-type: text/html\n\n";
> wholelist=containers[0].list_objects()
> random.shuffle(wholelist)
> newlist=[]
> try:
> del wholelist[int(sys.argv[1]):]
> while i < int(sys.argv[1]):
> newlist.append("http://example.com/"+wholelist[i].rstrip())
> i = i+1
> except IndexError, e:
> del newlist[5]
> print newlist
> ==
>
> The output I am seeing is as follows:
>
> ['http://example.com/wet-longhaireddachshund.jpg',
> 'http://example.com/dachshund2.jpg',
> 'http://example.com/dachshundingrass.jpg'] 
>
> Any tips on better coding practices are welcome, but please don't beat me up
>
> Thanks,
> vickistan
>
>
>

I don't see any arrays in that code, just lists.  i also don't see how
that program could produce exactly that ouput, as it also prints

"Content-type: text/html\n\n";

But if you literally mean that only the final newline is a problem, then
just end the print statement with a comma:
print newlist,

If you want more flexibility, instead of printing the list as a single
entity, you can just loop through it.  that way, you can choose which
newlines you want, if any.
for item in newlist:
print repr(item),#or many other variants.  But you probably
want some delimeter at least.
 

it's not clear what your other program is expecting for stdin, since
there is no single standard for "takes an array for input."  it's also
unclear why a trailing linefeed should hurt you.  But I hope this will
help some.


-- 

DaveA

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


Re: [Tutor] Help

2012-09-06 Thread Alan Gauld

On 06/09/12 09:35, Ray Jones wrote:


#A Python text-RPG
#A Jak Production
#APOC
global ammo


You use global inside a function not outside. All variables declared at 
the module level are global by definition.



ammo=55


This sets the global ammo value



def part1():
if answer == "SHOW" or answer == "Show" or answer == "show":
answer2 = raw_input("Type either Hand it over or flee")
if answer2 == "HAND IT OVER" or answer2 == "Hand it over" or answer2
== "hand it over":
print "Bandit: Good Job.. Go on now"
ammo=ammo-15


Here you try to create a local variable in the function butuse that 
variable in its definition.


What you really wanted was to use the global ammo. To do that you need 
to tell the function that any reference to ammo will use the global 
value, like this


def part1():
   global ammo

at the top of the function.

Ray added:

I'll take a stab at it. You are using attempting to modify a global
variable within a procedure. Procedure variables are separate from
global variables. Global variables must be passed into a procedure using
something on the order of 'part1(ammo)', and then returned back from the
procedure with a 'return '


That's not strictly true, as explained above. However, it is generally 
considered good programming practice not to rely on globals but to pass 
values in as parameters as you do in your example here.


So good practice says part1() should be defined as:

def part1(theAmmo, theFood, theLives):
# as is code...

Notice I changed the names to distinguish them from the global variables.
and you call it using the global variables as:

part1(ammo,food,lives)

The other thing to note is that at one point you use

return part1

That returns the function itself which is almost certainly not what you 
want.


You also return answer3 which doesn't seem to be defined anywhere.
Returning lots of different values from the same function will make it 
very hard to use. You should think about breaking this down into the 
code that gets the user responses and separate code that returns the 
required values, one value per function.


And finally at the end you call part() from within part(), that's a 
technique called recursion and can get you into all sorts of problems if 
you don't know what you are doing with it.


What you really want is a loop that repeats the input code until you get 
valid values. A while loop is probably best in this case.


--
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] Python

2012-09-06 Thread Alan Gauld

On 19/08/12 21:42, Andrew Rosen wrote:

I have a Windows Computer and I'm trying to make a shortcut on my
desktop that will run a program, so I don't have to open up a New Window
form Python Shell and use that to run the program. I can't figure out
how to do it, can you help me?


Create a shortcut to the python script in Windows explorer and drag that 
to your desktop.


If python is installed properly you should be able to double click it 
and python will run it.


If it's a console program you might need to add a line at the end like

raw_input('hit enter to quit')  # python v2.x
input('hit enter to quit')  # python v3.x

To prevent the program closing before you can see it.

--
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] Python 2.7.3, Pygame, and LiveWires

2012-09-06 Thread Alan Gauld

On 04/09/12 19:52, Jason Fremouw wrote:


packages listed above come as add-ons in my text book but are not
compatible with 2.7. Are these now built into the latest build of Python
or are they listed as different downloads on Python.org?


No, the livewires and pygame packages are not part of core python.
You will either need to find more recent versions of the packages that 
are compatible or downgrade python to a version that is compatible with 
the packages!


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] Hey.need help on time

2012-09-06 Thread Ray Jones
On 09/06/2012 02:08 AM, eryksun wrote:
> On Thu, Sep 6, 2012 at 4:25 AM, Ray Jones  wrote:
>> Why the additional step of calling time.tzset()? Once os.environ['TZ']
>> is set, I've found that time.localtime() responds to the new TZ without
>> anything extra. Is that a difference in versions (2.7.3 here)?
> It shouldn't strictly be necessary using glibc. I checked the source.
> glibc localtime calls __tz_convert() on each call, which calls
> tzset_internal() to update the TZ setting. However, I don't think
> that's guaranteed in all C runtimes. As the Python docs say,
> "[c]hanging the TZ environment variable without calling tzset *may*
> change the local timezone used by methods such as localtime, but this
> behaviour should not be relied on."
Got ya. I'll remember that.


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


Re: [Tutor] Doing the same thing twice. Works first time but not the second.

2012-09-06 Thread Omar Abou Mrad
On Fri, Aug 17, 2012 at 11:11 PM, Matthew Love  wrote:

>
> This is the error:
>
> Traceback (most recent call last):
>   File "C:\Users\Matthew\Desktop\test.py", line 16, in 
> print(player.inventory())
> TypeError: 'list' object is not callable
>
>
The python debugger can also give you a hint of how player.inventory
changed:

misc $ pdb test.py
-> class Player(object):
(Pdb) n
-> player = Player()
(Pdb) n
Player created.
-> player.inventory()
(Pdb) whatis player.inventory
*Function inventory*
(Pdb) n
-> player.inventory()
(Pdb) whatis player.inventory
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to print array without adding newline

2012-09-06 Thread Alan Gauld

On 19/08/12 02:17, vickistan wrote:

Hello: I am trying to output an array to another program that takes an array
as input


You are printing a list. You are not passing an 'array' to anything.
What exavctly does the other program expect to see. An array object - as 
defined in what language? or a list of strings? or something else.



the print statement adds a newline.


It also prints the string representation of your list.
If you want to print the contents of the list use a loop:

for item in arrayname: print item

That will give you the items each on a separate line but without the []

If you want it on a single line add a comma:

for item in arrayname: print item,  # python 2, python 3 is different

And if you don't want spaces use join():

print ''.join(arrayname)


of the array. Is there another way to print an array besides

print arrayname


See above. but without knowing what your other program expect an 'array' 
to look like we can't say what is best.



output as an array. Each element is a url. I call it from a browser, and it
works except for the added newline.


That suggests that you might actually want to create an html document?
If you need a file its best to create a file rather than rely on print 
statements. IMHO...



--
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] python 2.7.1

2012-09-06 Thread Alan Gauld

On 20/08/12 05:47, john wrote:

print"hello world"#this is just something to say





 >>> /Users/jonathan/Documents/hello.py


You don;t run Python scripts from the python prompt. You only type 
Python co0mmands there. You could import your file which wiull run it 
but the effect is slightly different. Its better to run scripts from the 
OS prompt


$ python /Users/jonathan/Documents/hello.py


--
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] Help

2012-09-06 Thread Walter Prins
Hi Ian,

On 4 September 2012 20:36, Ian o donovan  wrote:
> Hey, I am writing this to you because I want to know could you help.
> My school is doing enterprise and I want to enter.

What do you mean your school is "doing enterprise"?  Is it some
competition or something?

> I really want to
> make a program that will clean up your desktop E.G put files you
> haven't used for a while into a folder and delete your trash they are
> just a few ideas. I am trying to learn programming but I live in
> Ireland and where I live they is not much access to courses so I have
> to wait till college to learn programming. I have tried to learn some
> of python through on-line tutorials but find it hard So what I am
> asking is
> could you help me make a program if not I understand as I can imagine
> ye are very busy people.

You're at the right place to ask beginner Python questions.  Feel free
to try stuff and ask questions when you run into problems.  Be sure to
post complete error messages, what you've tried, what happened and
what you expected to happen instead.

As for courses, you may want to look into the following free
educational offerings where you can learn basic programming in a
structured manner:

https://www.coursera.org/course/interactivepython
http://www.udacity.com/overview/Course/cs101/CourseRev/apr2012
http://www.khanacademy.org/science/computer-science
https://www.edx.org/courses/HarvardX/CS50x/2012/about

Be sure to browse around the sites, most of the sites have multiple
courses available.

HTH

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


Re: [Tutor] how to print array without adding newline

2012-09-06 Thread Oscar Benjamin
On Sat, 18 Aug 2012 18:17:16 -0700 (PDT), vickistan 
 wrote:
Hello: I am trying to output an array to another program that takes 

an array
as input, but the print statement adds a newline. If it were adding 

to each
individual element, I could solve it easily, but it is adding one 

at the end
of the array. Is there another way to print an array besides 




print arrayname


Yes. You can use:

print arrayname,

Note the trailing comma ',' character at the end of the print 
statement. In python 2 this is the normal way to stop print from 
adding a newline. It's a silly syntax that has been fixed in python 
3. If your using python 3 then it looks like


print(arrayname, end='')

which makes a bit more sense to me.

By the way what your calling an array, python calls a list. In python 
the word array is usually used to refer to a number of other things.


As a more general comment: are you the author of both programs? If so 
then you can choose a different format for outputting your data. My 
default choice would be to print out each url on a separate line, 
without the square brackets or commas. You can do that with:


for url in arrayname:
   print url

Note that I want print to add the newlines. This is a common way of 
working with text files and this is the reason that print adds a 
newline.


Oscar

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


Re: [Tutor] How to get MAC address using Python at windows 7

2012-09-06 Thread bob gailer

On 8/18/2012 10:12 AM, šãñ wrote:


I need to find some way how i can get mac address of windows 7 in python.

Windows 7 does not have a MAC address. It is an operating system.

Ethernet adapters have MAC addresses. Your computer will have one or 
more Ethernet adapter.

From a command prompt enter
ipconfig /all

You will see something like (this is from MY computer, Windows 2008 
Server, similar to Win 7):


Windows IP Configuration

   Host Name . . . . . . . . . . . . : xxx
   Primary Dns Suffix  . . . . . . . : xxx
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : Yes
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : xxx

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) 82579LM Gigabit Network 
Connecti

on
   Physical Address. . . . . . . . . : 44-37-E6-63-86-B9
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : 
fe80::e102:17d6:8b9d:43be%10(Preferred)

   IPv4 Address. . . . . . . . . . . : 192.168.0.190(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 172242918
   DHCPv6 Client DUID. . . . . . . . : 
00-01-00-01-16-8E-75-AE-44-37-E6-63-86-B9


   DNS Servers . . . . . . . . . . . : ::1
   127.0.0.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter 
for VMnet

1
   Physical Address. . . . . . . . . : 00-50-56-C0-00-01
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : 
fe80::7c33:3774:7709:c50d%15(Preferred)

   IPv4 Address. . . . . . . . . . . : 192.168.29.1(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 419450966
   DHCPv6 Client DUID. . . . . . . . : 
00-01-00-01-16-8E-75-AE-44-37-E6-63-86-B9


   DNS Servers . . . . . . . . . . . : fec0:0:0:::1%1
   fec0:0:0:::2%1
   fec0:0:0:::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

etc.

Each Ethernet adapter has a Physical Address (MAC Address).

When you run ipconfig /all - if you see only one Physical Address, then 
that is the one you want.


If you see more than one then you must decide which Ethernet adapter you 
want.


Then you use Popen (in subprocess module) to run ipconfig /all, capture 
the output and parse it for the desired Ethernet adapter, then parse 
that section for the Physical Address.


There may be another (better?, easier?) way but this will work.

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


[Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
I have a multiple 'if' expression that I need to drastically reduce in
size, both for readability and to keep errors from creeping in.

For example, I would like to have the variable 'test' point to the a
location 'grid[rcount-1][ccount-1]' so that everywhere I would use
'grid.', I could replace it with 'test' How would I accomplish that?

Thanks.


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


Re: [Tutor] how to print array without adding newline

2012-09-06 Thread Dave Angel
On 09/06/2012 09:49 AM, vi...@thepenguin.org wrote:
> Thank you for your reply. I understand that it is odd, but my program is 
> being called from a hubot and returning data to it as well. I have figured 
> out how to make the changes to get it to output the correct data in the 
> correct format, but now I am getting a "Premature end of script headers" 
> error. I have the correct #! line and the output from the command line shows 
> no errors that would be interfering. Is there a way to make sure it is 
> showing me all the errors? To increase error logging?
> --
> !/usr/bin/env python

You top-posted, so I have to clip both the earlier messages out.  On
this forum, we put responses immediately AFTER the part we quoted.

I don't see how I can possibly help further, without buying a hubot of
my own.  I don't know what operating system you're running this on, nor
what the command lines look like.  I have no idea how the stdout of your
script migrates over to the hubot's processor.  Nor why it only gets
some of the stdout.

You could give us more environmental data (OS version, command line, any
messages, ...), or tell what the hubot's docs say you should use as a
format.


> import cloudfiles
> import random
> import sys
> import array
> 
> conn = cloudfiles.get_connection('username', 'key')
> 
> containers = conn.get_all_containers()
> i=0
> print "Content-type: text/html";

Perhaps you need a blank line to be output here.  One way is just print
by itself.

> wholelist=containers[0].list_objects()
> random.shuffle(wholelist)
> newlist=[]
> #newlist=wholelist[:]
> try:
> #print sys.argv[1]
> if "=" in sys.argv[1]: sys.argv[1] = sys.argv[1].rstrip("=")
> #print sys.argv[1]
> del wholelist[int(sys.argv[1]):]
> while i < int(sys.argv[1]):
> newlist.append("http://example.com/"+wholelist[i].rstrip())
> i = i+1
> except IndexError, e:

Where do you alert the user about this exception?

> del newlist[5]

> except Exception, err:
> print 'Caught an exception'

You should probably send this and any other error messages to stderr, as
stdout is presumably being consumed by the robot.

> print newlist,
> ---


-- 

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Dave Angel
On 09/06/2012 09:56 AM, Ray Jones wrote:
> I have a multiple 'if' expression that I need to drastically reduce in
> size, both for readability and to keep errors from creeping in.
>
> For example, I would like to have the variable 'test' point to the a
> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
> 'grid.', I could replace it with 'test' How would I accomplish that?
>
> Thanks.
>
>

Easiest way:   switch to C++

There is no preprocessor in Python, and no addresses.  There are some
places you could fake such stuff, but not the expression you have.

If I HAD to do something like this for Python, I'd write a
preprocessor.  But one reason I came to Python is its elegance, and a
preprocessor isn't elegant.

-- 

DaveA

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 07:15 AM, Dave Angel wrote:
> On 09/06/2012 09:56 AM, Ray Jones wrote:
>> I have a multiple 'if' expression that I need to drastically reduce in
>> size, both for readability and to keep errors from creeping in.
>>
>> For example, I would like to have the variable 'test' point to the a
>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>> 'grid.', I could replace it with 'test' How would I accomplish that?
>>
>> Thanks.
>>
>>
> Easiest way:   switch to C++
>
> There is no preprocessor in Python, and no addresses.  There are some
> places you could fake such stuff, but not the expression you have.
>
> If I HAD to do something like this for Python, I'd write a
> preprocessor.  But one reason I came to Python is its elegance, and a
> preprocessor isn't elegant.
Well, of all the.   a REAL programming language. I mean, even
Bash ;;))

Anyway, it was a shot. Thanks.


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Peter Otten
Ray Jones wrote:

> I have a multiple 'if' expression that I need to drastically reduce in
> size, both for readability and to keep errors from creeping in.
> 
> For example, I would like to have the variable 'test' point to the a
> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
> 'grid.', I could replace it with 'test' How would I accomplish that?

>>> class Grid(object):
... def __init__(self, rows):
... self.rows = rows
... def __getitem__(self, index):
... return self.rows[index]
... @property
... def test(self):
... return self[-1][-1]
... 
>>> grid = Grid([[1,2,3], [4,5,6], [7,8,9], [10,11,12]])
>>> grid[1]
[4, 5, 6]
>>> grid[1][2]
6
>>> grid.test
12


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Jerry Hill
On Thu, Sep 6, 2012 at 10:15 AM, Ray Jones  wrote:
> Well, of all the.   a REAL programming language. I mean, even
> Bash ;;))
>
> Anyway, it was a shot. Thanks.

There's almost certainly a way to accomplish your goal of simplifying
your giant nested if statements.  It just doesn't involve pointers.
Perhaps if you mocked up a representative example for us to look at
and play with, someone could come up with a suggestion.

For instance, if your set of if statements is emulating what would be
done with a case statement in other languages, dictionary based
dispatch may be a cleaner way to do the same thing in python.

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 07:33 AM, Peter Otten wrote:
> Ray Jones wrote:
>
>> I have a multiple 'if' expression that I need to drastically reduce in
>> size, both for readability and to keep errors from creeping in.
>>
>> For example, I would like to have the variable 'test' point to the a
>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>> 'grid.', I could replace it with 'test' How would I accomplish that?
 class Grid(object):
> ... def __init__(self, rows):
> ... self.rows = rows
> ... def __getitem__(self, index):
> ... return self.rows[index]
> ... @property
> ... def test(self):
> ... return self[-1][-1]
> ... 
Excellent! Now I am going to save this message for the time when I've
advanced to classes and objects! Thanks, Peter.


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Dave Angel
On 09/06/2012 10:15 AM, Ray Jones wrote:
> On 09/06/2012 07:15 AM, Dave Angel wrote:
>> On 09/06/2012 09:56 AM, Ray Jones wrote:
>>> I have a multiple 'if' expression that I need to drastically reduce in
>>> size, both for readability and to keep errors from creeping in.
>>>
>>> For example, I would like to have the variable 'test' point to the a
>>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>>> 'grid.', I could replace it with 'test' How would I accomplish that?
>>>
>>> Thanks.
>>>
>>>
>> Easiest way:   switch to C++
>>
>> There is no preprocessor in Python, and no addresses.  There are some
>> places you could fake such stuff, but not the expression you have.
>>
>> If I HAD to do something like this for Python, I'd write a
>> preprocessor.  But one reason I came to Python is its elegance, and a
>> preprocessor isn't elegant.
> Well, of all the.   a REAL programming language. I mean, even
> Bash ;;))
> 
> Anyway, it was a shot. Thanks.
> 
> 

I don't know your use-case.  For that matter, I don't even know what
semantics you mean by the grid[xx][yy] expression.  For example, are
grid, rcount, and ccount globals?  Or are you constraining 'test' to
only be used in the context where they are all visible?   Or are you
defining this location as the offset within grid where rcount and ccount
happen to point to right now?  I can see maybe a dozen "reasonable"
meanings, each requiring a different sets of constructs in the language
or its preprocessor.

One thing you can do in Python, but not in any other language I've used,
is to define a class instance property.  For example, if you were
willing to use q.test instead of test, you could do something like:

class Q(object):
@property
def test(self):
return grid[rcount-1][ccount-1]

That would give you readonly access to an object defined by 3 variables
that have to be visible to the Q code.  And you could make the
expression more complex if grid is defined elsewhere, for example.

Now once you do  q = Q(), you can use
q.test  instead of the larger expression.

Lots of other possibilities in Python.  But not with exactly your
original syntax.  Using this one as is would be ugly code, as is your
original example.  So presumably you have an actual use-case where this
makes sense, other than saving typing.

-- 

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 07:35 AM, Jerry Hill wrote:
> On Thu, Sep 6, 2012 at 10:15 AM, Ray Jones  wrote:
>> Well, of all the.   a REAL programming language. I mean, even
>> Bash ;;))
>>
>> Anyway, it was a shot. Thanks.
> There's almost certainly a way to accomplish your goal of simplifying
> your giant nested if statements.  It just doesn't involve pointers.
> Perhaps if you mocked up a representative example for us to look at
> and play with, someone could come up with a suggestion.
>
> For instance, if your set of if statements is emulating what would be
> done with a case statement in other languages, dictionary based
> dispatch may be a cleaner way to do the same thing in python.
>
Thanks for the reply, Jerry. I actually can do it relatively easily with
just a few nested 'if' statements.I was trying multiple tests within
the same 'if' statement. I'm simplifying it by changing into a 0-based
loop rather than a 1-based loop (don't have to worry about the '-1'
stuff). I'm not certain where I'm going with it yet - it's a udacity
assignment that I'm still trying to work out in my head.


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 07:48 AM, Dave Angel wrote:
>>> On 09/06/2012 09:56 AM, Ray Jones wrote:
 I have a multiple 'if' expression that I need to drastically reduce in
 size, both for readability and to keep errors from creeping in.

 For example, I would like to have the variable 'test' point to the a
 location 'grid[rcount-1][ccount-1]' so that everywhere I would use
 'grid.', I could replace it with 'test' How would I accomplish that?

 Thanks.


>>>
> I don't know your use-case.  For that matter, I don't even know what
> semantics you mean by the grid[xx][yy] expression.  For example, are
> grid, rcount, and ccount globals?  Or are you constraining 'test' to
> only be used in the context where they are all visible?   Or are you
> defining this location as the offset within grid where rcount and ccount
> happen to point to right now?  I can see maybe a dozen "reasonable"
> meanings, each requiring a different sets of constructs in the language
> or its preprocessor.
>
> One thing you can do in Python, but not in any other language I've used,
> is to define a class instance property.  For example, if you were
> willing to use q.test instead of test, you could do something like:
>
> class Q(object):
> @property
> def test(self):
> return grid[rcount-1][ccount-1]
>
> That would give you readonly access to an object defined by 3 variables
> that have to be visible to the Q code.  And you could make the
> expression more complex if grid is defined elsewhere, for example.
>
> Now once you do  q = Q(), you can use
> q.test  instead of the larger expression.
>
> Lots of other possibilities in Python.  But not with exactly your
> original syntax.  Using this one as is would be ugly code, as is your
> original example.  So presumably you have an actual use-case where this
> makes sense, other than saving typing.
>
Basically it's as simple as ensuring that an array consists of integers,
and that those integers fall within a certain range. Rather than using
multiple 'if' statements, I was (am, at this point) using multiple tests
within a single 'if' statement. Nothing earth-shatteringly difficult,
but I was simply looking for a way to shorten the overall test
expression with a recursive(? is that the term) variable. No problem though.

Thanks.


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Walter Prins
Hi Ray,

On 6 September 2012 15:59, Ray Jones  wrote:
> Basically it's as simple as ensuring that an array consists of integers,
> and that those integers fall within a certain range. Rather than using
> multiple 'if' statements, I was (am, at this point) using multiple tests
> within a single 'if' statement. Nothing earth-shatteringly difficult,
> but I was simply looking for a way to shorten the overall test
> expression with a recursive(? is that the term) variable. No problem though.

By array I suppose you mean "list of lists of items"?

Anyway, if you have such a structure, and you want to "visit" each in
turn to check it, you can do this:

for sublist in grid:
for item in sublist:
# code to check if "item" is in range goes here

The above obviously doesn't actually track the "row" or "column"
you're checking.  If you'd like to keep track of what "row"/"column"
you're on, you can for example do:

for row, sublist in enumerate(grid):
for col, item in enumerate(sublist):
# code to check if "item" is in range goes here

HTH,

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Oscar Benjamin
On 2012-09-06, Ray Jones  wrote:
>
> Basically it's as simple as ensuring that an array consists of integers,
> and that those integers fall within a certain range. Rather than using
> multiple 'if' statements, I was (am, at this point) using multiple tests
> within a single 'if' statement. Nothing earth-shatteringly difficult,
> but I was simply looking for a way to shorten the overall test
> expression with a recursive(? is that the term) variable. No problem though.
>
> Thanks.

How about using a generator expression with all()? For example:

>>> def isint(n):
... return int(n) == n
...
>>> def isinrange(n, a, b):
... return a <= n <= b
...
>>> numbers = [11, 12, 14, 15]
>>> all(isint(x) and isinrange(x, 10, 20) for x in numbers)
True
>>> numbers[0] = 9
>>> numbers
[9, 12, 14, 15]
>>> all(isint(x) and isinrange(x, 10, 20) for x in numbers)
False
>>> numbers[0] = 14.5
>>> all(isint(x) and isinrange(x, 10, 20) for x in numbers)
False


Oscar

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 08:29 AM, Walter Prins wrote:
> Hi Ray,
>
> On 6 September 2012 15:59, Ray Jones  wrote:
>> Basically it's as simple as ensuring that an array consists of integers,
>> and that those integers fall within a certain range. Rather than using
>> multiple 'if' statements, I was (am, at this point) using multiple tests
>> within a single 'if' statement. Nothing earth-shatteringly difficult,
>> but I was simply looking for a way to shorten the overall test
>> expression with a recursive(? is that the term) variable. No problem though.
> By array I suppose you mean "list of lists of items"?
Yes.
> Anyway, if you have such a structure, and you want to "visit" each in
> turn to check it, you can do this:
>
> for sublist in grid:
> for item in sublist:
> # code to check if "item" is in range goes here
>
> The above obviously doesn't actually track the "row" or "column"
> you're checking.  If you'd like to keep track of what "row"/"column"
> you're on, you can for example do:
>
> for row, sublist in enumerate(grid):
> for col, item in enumerate(sublist):
> # code to check if "item" is in range goes here
Our homework "monitor" complains if we use code that hasn't been
discussed in session yet. We haven't even progressed to 'range' in the
for loops yet - I don't think 'enumerate' would be appreciated. lol 
Technically, any variable pointer that I had managed to drum up here
would have been frowned upon, but I didn't figure it would have been a
serious breach.

I've got a pretty good handle on doing it the "hard way". I'm swatting
bugs right now... :))


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


Re: [Tutor] python wifi

2012-09-06 Thread Emile van Sebille

On 9/5/2012 9:43 PM Sales said...

Hello,
I'm trying to install python wifi using easy install. I have python27 and 
working on mac os. from a shell I'm running:

easy_install python_wifi-0.5.0-py2.5.egg

I also tried:

sudo easy_install python_wifi-0.5.0-py2.5.egg



Now try the "[sudo ]easy_install python_wifi" variants.  IIRC, the py2.5 
in the egg name indicated compatibility for python .25 and you've said 
you've got 2.7 installed so let'd first try to let it pick the 
compatible version and see what we get.


Emile


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


Re: [Tutor] how to print array without adding newline

2012-09-06 Thread Alan Gauld

On 06/09/12 15:10, Dave Angel wrote:


except Exception, err:
 print 'Caught an exception'


You should probably send this and any other error messages to stderr, as
stdout is presumably being consumed by the robot.


And you probably shouldn't use such a bland error message for every 
possible error. At the very least print the error type but better

still store the error data in a log file if you can't just print
it out.

--
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] python wifi

2012-09-06 Thread Jerry Hill
On Thu, Sep 6, 2012 at 12:43 AM, Sales  wrote:
> Hello,
> I'm trying to install python wifi using easy install. I have python27 and 
> working on mac os. from a shell I'm running:
>
> easy_install python_wifi-0.5.0-py2.5.egg

The "py2.5" in the file name suggests that you're trying to install a
version of this code that was compiled for python 2.5.  If you're
using python 2.7, as you say, that isn't going to work.  Also, the
project's homepage on the cheeseshop says "Python WiFi is a Python
module that provides read and write access to a wireless network
card's capabilities using the Linux Wireless Extensions".

Does Mac OS X support the Linux Wireless Extensions?  If not, I don't
think this package is going to be of any help to you at all.

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Alan Gauld

On 06/09/12 14:56, Ray Jones wrote:

I have a multiple 'if' expression that I need to drastically reduce in
size, both for readability and to keep errors from creeping in.

For example, I would like to have the variable 'test' point to the a
location 'grid[rcount-1][ccount-1]' so that everywhere I would use
'grid.', I could replace it with 'test' How would I accomplish that?



I may have missed some messages but this is context free.
What are these multiple if statements?
Why would "reducing" them improve readability? It might make them 
shorter but more cryptic.


As to the other question, is

test = grid[rcount-1][ccount-1]

too obvious?

--
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] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 10:05 AM, Alan Gauld wrote:
> On 06/09/12 14:56, Ray Jones wrote:
>> I have a multiple 'if' expression that I need to drastically reduce in
>> size, both for readability and to keep errors from creeping in.
>>
>> For example, I would like to have the variable 'test' point to the a
>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>> 'grid.', I could replace it with 'test' How would I accomplish that?
>
>
> I may have missed some messages but this is context free.
> What are these multiple if statements?
> Why would "reducing" them improve readability? It might make them
> shorter but more cryptic.
>
> As to the other question, is
>
> test = grid[rcount-1][ccount-1]
>
> too obvious?
>
I went out to the kitchen for a bit to eat an hour or so ago and
suddenly did a face-palm! Duh!

I'm going to have to quit dog-sitting for my niece - these all-nighters
are killing my thinking ability!


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


Re: [Tutor] Help

2012-09-06 Thread Mark Lawrence

On 03/09/2012 15:39, Jack Little wrote:

Ok, I am somewhat new to python, and I am making a text-based RPG. I get a
weird error with this code:


[snip]





Thanks,
Jack Little




Further to the sound advice you've already been given a rather more 
informative subject line would have been helpful :)  My apologies if 
someone has already said this and I've missed it.


--
Cheers.

Mark Lawrence.

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Steven D'Aprano

On 06/09/12 23:56, Ray Jones wrote:

I have a multiple 'if' expression that I need to drastically reduce in
size, both for readability and to keep errors from creeping in.

For example, I would like to have the variable 'test' point to the a
location 'grid[rcount-1][ccount-1]' so that everywhere I would use
'grid.', I could replace it with 'test' How would I accomplish that?


Um, am I missing something blindingly obvious here?

What about this?

test = grid[rcount-1][ccount-1]  # I can never think of good names...
if test < 1:
process(test)
elif test == 1:
do_something_different(test, 2, 3, 4)
elif 1 < test <= 100:
do_another_thing(test, "ham", "cheese")
# and so on...



--
Steven

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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Steven D'Aprano

On 07/09/12 01:33, Ray Jones wrote:


Our homework "monitor" complains if we use code that hasn't been
discussed in session yet.


The good old "teaching by enforced ignorance" method.



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


Re: [Tutor] How to get MAC address using Python at windows 7

2012-09-06 Thread Steven D'Aprano

On 06/09/12 23:44, bob gailer wrote:

On 8/18/2012 10:12 AM, šãñ wrote:


I need to find some way how i can get mac address of windows 7 in python.

Windows 7 does not have a MAC address. It is an operating system.

Ethernet adapters have MAC addresses. Your computer will have one or more
Ethernet adapter.


Just to be pedantic, your computer will have ZERO or more Ethernet adapters.
Although if you are receiving email and getting on the Internet on your
computer, it must have at least one.



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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 05:31 PM, Steven D'Aprano wrote:
> On 06/09/12 23:56, Ray Jones wrote:
>> I have a multiple 'if' expression that I need to drastically reduce in
>> size, both for readability and to keep errors from creeping in.
>>
>> For example, I would like to have the variable 'test' point to the a
>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>> 'grid.', I could replace it with 'test' How would I accomplish that?
>
> Um, am I missing something blindingly obvious here?
>
> What about this?
>
> test = grid[rcount-1][ccount-1]  # I can never think of good names...
> if test < 1:
> process(test)
> elif test == 1:
> do_something_different(test, 2, 3, 4)
> elif 1 < test <= 100:
> do_another_thing(test, "ham", "cheese")
> # and so on...
>
No, you're not missing something blindingly obvious - I was! 


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


Re: [Tutor] Making big 'uns into little 'uns

2012-09-06 Thread Ray Jones
On 09/06/2012 05:34 PM, Steven D'Aprano wrote:
> On 07/09/12 01:33, Ray Jones wrote:
>
>> Our homework "monitor" complains if we use code that hasn't been
>> discussed in session yet.
>
> The good old "teaching by enforced ignorance" method.
>
Actually I like what they're doing. First of all, this is a CS101 class
- not a Python class.

I've done some (relatively - from my viewpoint) advanced programming  by
knowing what I wanted to accomplish and finding a (in the past) Bash
tool to accomplish it. In fact, as I've been converting my Bash scripts
to Python, I've been doing pretty much the same thing (which is why I
subscribed to this list ;) ).

But somewhere along the line I will be trying to do something that a
specific tool won't accomplish: I'll have to use my brain! I've never
known what I could and could not accomplish without another, stronger,
tool, so I never really tried. Now I'm learning to apply my mind to
problems that I KNOW can be accomplished with basic code and applying my
mind to solving the problems. ;)


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