[Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread michelle_low



Hi everyone,




Can someone please help me with the following phyton script? I received the 
error message  DeprecationWarning: the sets module is deprecated
  from sets import Set.


After googling, I have tried the methods others suggest:  change sets to set or 
delete the from sets import Set but none of them works. 


Can someone suggest me how to modify the following codes so that the input file 
is read from standard input?
I'd like to execute them with unix command 


script.py <  sequence.fna




Thanks a bunch.





#!/usr/local/bin/python


import math
from sets import Set




line = file("sequence.fna", "r")


for x in line:
  if x [0] == ">" :


#determine the length of sequences
s=line.next()
s=s.rstrip()
length = len(s)


# determine the GC content
G = s.count('G')
C = s.count('C')
GC= 100 * (float(G + C) / length)
   


stList = list(s)
alphabet = list(Set(stList))


freqList = []
for symbol in alphabet:
  ctr = 0
  for sym in stList:
if sym == symbol:
ctr += 1

freqList.append(float(ctr)/len(stList))


# Shannon entropy
  ent = 0.0
  for freq in freqList:
ent = ent + freq * math.log(freq, 2)
  ent = -ent


  print x
  print "Length:" , length

  print "G+C:" ,round(GC),"%"
  print 'Shannon entropy:'
  print ent
  print 'Minimum number of bits required to encode each symbol:'
  print int(math.ceil(ent))





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


Re: [Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread Peter Otten
michelle_low wrote:

> Can someone please help me with the following phyton script? I received

Python; write it on the blackboard one hundred times ;)

> the error message  DeprecationWarning: the sets module is deprecated
>   from sets import Set.
 
> After googling, I have tried the methods others suggest:  change sets to
> set or delete the from sets import Set but none of them works.

Remove the line

from  sets import Set

completely and replace Set with set everywhere in your code.

> Can someone suggest me how to modify the following codes so that the input
> file is read from standard input? I'd like to execute them with unix
> command

Replace the line

> line = file("sequence.fna", "r")

with

import sys
line = sys.stdin

If you want to go fancy you can accept either a file name or read from stdin 
with

import sys
if sys.argv > 1:
# filename was passed as an argument to the script
line = open(sys.argv[1])
else:
# no filename was passed, default to stdin
line = sys.stdin


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


Re: [Tutor] Beep sound

2013-03-24 Thread eryksun
On Sun, Mar 24, 2013 at 12:38 AM, Phil  wrote:
> On 24/03/13 12:18, Steven D'Aprano wrote:
>> Nonsense. Not only does echo exist as a command on any Unix, including
>> Apple Mac OS, FreeBSD, OpenBSD, Solaris and others, it also exists on
>> Windows and DOS:
> I don't want to appear augmentative but there is no echo -e command for
> Windows. There is, however, echo without the 'e' switch.

PulseAudio also suggests that you're using Linux or BSD, though I
think it does have ports for OS X and Windows.

The ossaudiodev module exists on Linux/BSD, so try something
relatively simple like outputting a square wave to /dev/dsp. Here's an
example device configuration:

format = ossaudiodev.AFMT_U8  # unsigned 8-bit
channels = 1
rate = 8000  # samples/second
strict = True

dsp = ossaudiodev.open('/dev/dsp', 'w')
dsp.setparameters(format, channels, rate, strict)

Say you want a 1000 Hz, 50% duty-cycle square wave. Given the rate is
8000 sample/s, that's 8 samples per cycle. In 8-bit mode, a cycle has
four bytes at the given amplitude followed by four null bytes. For a
0.5 s beep, you need 0.5 * 1000 = 500 cycles.

In general:

amp = chr(amplitude)  # bytes([amplitude]) in 3.x
cycles = int(duration * frequency)
nhalf = int(0.5 * rate / frequency)
data = (amp * nhalf + b'\x00' * nhalf) * cycles

Then just write the data. Make sure to close the device when you no
longer need it.

dsp.write(data)
dsp.close()

You can use threading to play the beep in the background without
blocking the main thread. To me this is simpler than juggling partial
writes in nonblock mode. However, you can't access the device
concurrently. Instead you could make beep() a method. Then queue the
requests, to be handled sequentially by a worker thread.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread Alan Gauld

On 24/03/13 07:45, michelle_low wrote:


Can someone please help me with the following phyton script? I
received the error message  DeprecationWarning: the sets module is
deprecated
   from sets import Set.



I'd like to execute them with unix command


Peter answered both of these.
However, I think there may be a bug in your code...



 freqList = []
 for symbol in alphabet:
   ctr = 0
   for sym in stList:
 if sym == symbol:
 ctr += 1
 freqList.append(float(ctr)/len(stList))



Should the last line not be indented to be part of the first for loop?
Otherwise you only store the count for the last symbol.

BTW this could be made simpler:

freqList = []
for symbol in alphabet:
   val = float(stList.count(symbol)/len(stlist)
   freqList.append(val)

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] Python based SMB 2.1/3 testing tool

2013-03-24 Thread Alan Gauld

On 24/03/13 04:05, Pankaj Agarwal wrote:


I'm looking for a tool like PySMB which can provide support for SMB 2.1.
Any references will be appreciated.


This list is for learning the Python language and its core
libraries. I suspect you might get a better response for
this type of specialist question on the main Python
mailing list/newsgroup

comp.lang.python

--
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 based SMB 2.1/3 testing tool

2013-03-24 Thread Pankaj Agarwal
Thanks Alan!


On Sun, Mar 24, 2013 at 2:13 AM, Alan Gauld wrote:

> On 24/03/13 04:05, Pankaj Agarwal wrote:
>
>  I'm looking for a tool like PySMB which can provide support for SMB 2.1.
>> Any references will be appreciated.
>>
>
> This list is for learning the Python language and its core
> libraries. I suspect you might get a better response for
> this type of specialist question on the main Python
> mailing list/newsgroup
>
> comp.lang.python
>
> --
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a simple python project

2013-03-24 Thread Leam Hall

On 03/22/2013 05:02 AM, miguel.gua...@hushmail.com wrote:

Greetings all!


My name is Miguel Guasch, I'm a software tester who's trying to
slowly get into automation, and eventually (in a couple of years)
into development.


Miguel, welcome!

Depending on your skills, you might want to look up the Python classes 
on Coursera.org. They are free, challenging, and some offer a 
certificate of achievement. That might be useful in your work portfolio 
when you move to developer.


Last year's videos for one beginner class are still on-line:
https://class.coursera.org/programming1-2012-001/class/index

The follow up class for that starts tomorrow:
https://www.coursera.org/course/programming2

There's an introductory class starting in a few weeks:
https://www.coursera.org/course/interactivepython

And a Programming Design class starts in May:
https://www.coursera.org/course/programdesign

Note that I'm not affiliated with Coursera, except to take their 
classes. Of course, I'm a believer in open education, too.


Leam

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


Re: [Tutor] Beep sound

2013-03-24 Thread Phil

On 24/03/13 18:24, eryksun wrote:



PulseAudio also suggests that you're using Linux or BSD, though I
think it does have ports for OS X and Windows.

The ossaudiodev module exists on Linux/BSD, so try something
relatively simple like outputting a square wave to /dev/dsp. Here's an
example device configuration:

 format = ossaudiodev.AFMT_U8  # unsigned 8-bit
 channels = 1
 rate = 8000  # samples/second
 strict = True

 dsp = ossaudiodev.open('/dev/dsp', 'w')
 dsp.setparameters(format, channels, rate, strict)

Say you want a 1000 Hz, 50% duty-cycle square wave. Given the rate is
8000 sample/s, that's 8 samples per cycle. In 8-bit mode, a cycle has
four bytes at the given amplitude followed by four null bytes. For a
0.5 s beep, you need 0.5 * 1000 = 500 cycles.

In general:

 amp = chr(amplitude)  # bytes([amplitude]) in 3.x
 cycles = int(duration * frequency)
 nhalf = int(0.5 * rate / frequency)
 data = (amp * nhalf + b'\x00' * nhalf) * cycles

Then just write the data. Make sure to close the device when you no
longer need it.

 dsp.write(data)
 dsp.close()

You can use threading to play the beep in the background without
blocking the main thread. To me this is simpler than juggling partial
writes in nonblock mode. However, you can't access the device
concurrently. Instead you could make beep() a method. Then queue the
requests, to be handled sequentially by a worker thread.


Thanks Erksun for your detailed reply. I've saved your reply for a rainy 
day.


I had discovered some information about writing to the dsp device since 
my original post. However, my experiments have been temporarily 
curtailed by a wife who wants me to spent more time building our house 
and less time playing with the computer.


It's amazing what's available to play with these days.

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


Re: [Tutor] Beep sound

2013-03-24 Thread Bod Soutar
> Thank you for your reply Bodsda,
>
> Actually, I didn't think there was any need to make any guesses since "echo
> -e" is exclusively a Linux command. Anyway, I had already spent some time
> searching for an answerer and the answer given most often was to "modprobe
> pcspkr". This didn't lead to a working beep.
>
> As I said previously, I'm was only curious and it's of little importance.
> There are many methods, some more complex than others, to play sound files.
> I found that the pygame library is the easiest to use.
>
> Thank you again for taking the time to answer.
>
> --
> Regards,
> Phil
>

Your on the right track, the other thing I've seen is pcspkr being
blacklisted. Look in /etc/modprobe.d/blacklist.conf for a line like
'blacklist pcspkr' if it's there, remove it then modprobe or reboot
and it should be working again.

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


Re: [Tutor] Beep sound

2013-03-24 Thread xDog Walker
On Friday 2013 March 22 18:48, Phil wrote:
> Just out of curiosity how can a beep sound be generated?
>
> My interest in this came about because echo -e '\a' no longer works.
> Also print '\a' doesn't work, presumably for the same reason. The
> following is also mute:
>
> import Tkinter
> Tkinter.Tk().bell()
>
> Print '\a', under Idle, causes a bell icon to be displayed so it seems
> that the lack of a beep is due to a system setting.
>
> A Google search has shown several methods to play .wav files, some
> easier than others. Perhaps Pulse Audio has made '\a' redundant?

Maybe something here:

http://code.activestate.com/search/recipes/#q=beep

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: [Tutor] Phyton script for fasta file (seek help)

2013-03-24 Thread Peter Otten
michelle_low wrote:

> Hi Peter,
> Thanks for your help.

You're welcome. In the future, please send your mail to the list, not to an 
individual poster. That way more people get a chance to read it and you are 
more likely to get help.

> I have followed your advice:
> 
> 
> -removed the line
> 
> from sets import Set
> 
> completely and replace Set with set
> 
> 
> -Replace the line
> 
> > line = file("sequence.fna", "r")
> 
> with
> 
> import sys
> line = sys.stdin

> However, when I tried to run the script using command ./script.py <
> sequence.fna . nothing came up. The code just does't run. I used to be 
able
> to execute the code and it printed out the list. Now I'm clueless and 
stuck again.

If it worked to your satisfaction before I suggest that you doublecheck you 
didn't accidentally make changes other than those I suggested.

> Can you please look at my script below? Thanks a million

I'd rather not ;) Seriously, without a clear notion of what the script is 
supposed to do it is hard to fix its behaviour...

> #!/usr/local/bin/python
> 
> 
> import math
> import sys
> 
> 
> line = sys.stdin
> 
> 
> for x in line:
>   if x [0] == ">" :

I suppose that's a ">" in your actual code. Otherwise the condition is 
always False -- which would explain why you see nothing.
 
> #determine the length of sequences
> s=line.next()
> s=s.rstrip()
> length = len(s)
> 
> 
> # determine the GC content
> G = s.count('G')
> C = s.count('C')
> GC= 100 * (float(G + C) / length)
> 
> 
> 
> 
> stList = list(s)
> alphabet = list(set(stList))
> 
> 
> freqList = []
> for symbol in alphabet:
>   ctr = 0
>   for sym in stList:
> if sym == symbol:
> ctr += 1
> 
>freqList.append(float(ctr)/len(stList))

The above line gave me an IndentationError. It should probably be

>   freqList.append(float(ctr)/len(stList))

Had you answered Alan (publicly) there'd be no need to guess...

> # Shannon entropy
>   ent = 0.0
>   for freq in freqList:
> ent = ent + freq * math.log(freq, 2)
>   ent = -ent
> 
> 
>   print x
>   print "Length:" , length
>   print "G+C:" ,round(GC),"%"
>   print 'Shannon entropy:'
>   print ent
>   print 'Minimum number of bits required to encode each symbol:'
>   print int(math.ceil(ent))

PS: if you reuse code from someone else: 

it's a good idea to give credits.

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


[Tutor] A Text Adventure Problem

2013-03-24 Thread John Bochicchio
I've been trying to write a simple test text adventure, but have been
running into serious problems. Here is the error I get when I run it. It
will give me the opening text and lets me make my first choice. Then I get
this.

error "Traceback: (Most recent call last)
file "game1.py", line 104, in 
RUNNER (ROOMS, shack_front)
file "game1.py", line 100 in runner
room = map[next]
keyerror= none

And here is my code.

from sys import exit

from random import randint



def death():

quips = ["You've become a zombie and eat you pals. Douche."

 "You've died and left your comrades to fend for themselves.
Douche"

 "Your whole group dies because of you. Douche."

 "You've got terrible planning skills, and ruined the teams
chances of survival. Douche."]



print quips[randint(0, len(quips)-1)]

exit(1)





def shack_front():

print "The year is 2062, and the zombies have risen. You're not a
doctor, and you have no training. You're just a guy trying to survive."

print ".." * 8

print "You stand in front of a broken down shack, you here gurgles and
screams from inside. There is a window to the side of the house that you
can see through, or a door you can burst into."

print ".." * 8

print "Window or door?"



action = raw_input(">")



if action == "window":

print "You silently walk over to the dirty window. You look inside
to see a man held captive by 2 marauders. The marauders are armed with
bats, and don't seem to know what they're doing. You have 1 9mm glock with
12 bullets."



elif action == "door":

 print "You burst through the door with your shoulder. You see only
one marauder. You shoot him in the chest and notice a man tied up in a
chair. You walk over to him but feel a sharp pain in the back of your head.
You never saw the second marauder coming."

 return 'death'



else:

print "Not a valid command"

return 'shack_front'



def shack_window():

print "Do you burst through the door or try to fire through the window
at the marauders?"



action = raw_input(">")



if action == "window":

print "You fire off three shots through the window. Two in the
chest of the first marauder, one in the neck of the other. They fall to the
ground, dead. You walk inside to see if the man is okay."



elif action == "door":

print "You burst through the door and fire two shots into the first
marauder. You remember seeing two, so you turn around and put one bullet
through the head of the one behind you. You walk over to the man to see if
he's okay."



else:

print "Not a valid command"

return 'shack_window'



def shack_interior():

print "You ask the man if he is okay."

print "He says that he will be fine, and that his name is Carmicheal."

print "He says he is an ex marine, but was ambushed by five of them. He
believes that three went out on a scavenging party."

print "Carmicheal believes that if you wait for them to come back and
ambush them, you will be able to get food, ammo, and perhaps even a gun."

print "Do you tell him yes, or no?"



action = raw_input(">")



if action == "yes":

print "You tell Carmicheal yes. You both hide in the back of the
shack. Carmicheal takes a cleaver and you pull out your glock. 30 minutes
pass."

print ".." * 10



elif action == "no":

print "Carmicheal looks at you puzzled. You ask if he wants to come
with you, but he only gets mad. He screams at you for not following the
plan, but you walk out."

print "You hear a rush of sound as the cleaver hits the back of
your skull. You are dead."

return 'death'



else:

print "Not a valid command"

return 'shack_interior'



def shack_back():

print "You hear the sound of boots in the next room. Carmicheal and you
stand up, ready to attack. Do you go in first, or him?"



action = raw_input(">")



if action == "him":

print "Carmicheal goes in first. His cleaver tearing through the
neck of the first marauder. You see one trying to pull the gun from his
waist. You fire two shots into the marauder, killing him. The third
marauder grabs you from behind. You elbow him in the abdomen, leaving
Carmicheal just enough room to throw his cleaver into the marauder's head."

print "You have both survived. Do you scavenge the dead bodies?"



elif action == "me":

 print "You go in first. You see the three marauders lined up like
bowling pins. You let off six shots. Killing first the marauder with the
gun, then the two with knives and bats. You easily killed these men without
even breaking a sweat. Their bodies lay before you. Do you want to scavenge
them?"



else:

print "Not a valid command."

return 'shack_back'



ROOMS = {

'death': death,

'shack_front': shack_front,

'shack_window': shack_wi

Re: [Tutor] A Text Adventure Problem

2013-03-24 Thread bob gailer

On 3/24/2013 3:41 PM, John Bochicchio wrote:
I've been trying to write a simple test text adventure, but have been 
running into serious problems. Here is the error I get when I run it. 
It will give me the opening text and lets me make my first choice.

What did you enter? I will bet is was 'window'.

Then I get this.

error "Traceback: (Most recent call last)
file "game1.py", line 104, in 
RUNNER (ROOMS, shack_front)
file "game1.py", line 100 in runner
room = map[next]
keyerror= none


[snip]

Questions:
1 - what are you using to run your code?
2 - Version of Python?
3 - Operating system?
4 - Did you think about what the error might mean?

Observations:

1 - The traceback does not match your code, so either you retyped it or 
you are using some unusual way of running the program.


Compare
RUNNER (ROOMS, shack_front)
with
runner (ROOMS, 'shack_front')

2 - the error normally would look like KeyError: None rather than 
keyerror= none


3 - The various room functions have at least one way out of them with no 
return statement. The value returned in that case is None.


4 - There are many many blank lines in the program making it much harder 
to read. In future eliminate most or all of them.


5 - Most of us do not have the patience to count down 100 lines. In 
future flag the line with something like:

room = map[next] < line 100

6 - quips = ["You've become a zombie and eat you pals. Douche."
 "You've died and left your comrades to fend for 
themselves. Douche"

 "Your whole group dies because of you. Douche."
 "You've got terrible planning skills, and ruined the teams 
chances of survival. Douche."]
quips is a list with one element, consisting of one string or 244 
characters.

print quips[randint(0, len(quips)-1)]
will always print the entire string.
Perhaps you meant to put a comma at the end of each line?

HTH and good luck.

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


Re: [Tutor] A Text Adventure Problem

2013-03-24 Thread John Bochicchio
1. I'm using the terminal to run the code. Using the command - (cd python
&& python2 game1.py)
2. Using python 2.6 I believe.
3. I'm running Arch Linux at the moment.
4. I'm new to python, but I assume the error must have something to do with
not having a way for the program to move to the next area of the code.


On Sun, Mar 24, 2013 at 4:58 PM, bob gailer  wrote:

>  On 3/24/2013 3:41 PM, John Bochicchio wrote:
>
> I've been trying to write a simple test text adventure, but have been
> running into serious problems. Here is the error I get when I run it. It
> will give me the opening text and lets me make my first choice.
>
> What did you enter? I will bet is was 'window'.
>
>  Then I get this.
>
>  error "Traceback: (Most recent call last)
> file "game1.py", line 104, in 
> RUNNER (ROOMS, shack_front)
> file "game1.py", line 100 in runner
> room = map[next]
> keyerror= none
>
>   [snip]
>
> Questions:
> 1 - what are you using to run your code?
> 2 - Version of Python?
> 3 - Operating system?
> 4 - Did you think about what the error might mean?
>
> Observations:
>
> 1 - The traceback does not match your code, so either you retyped it or
> you are using some unusual way of running the program.
>
> Compare
> RUNNER (ROOMS, shack_front)
> with
> runner (ROOMS, 'shack_front')
>
> 2 - the error normally would look like KeyError: None rather than keyerror=
> none
>
>  3 - The various room functions have at least one way out of them with no
> return statement. The value returned in that case is None.
>
> 4 - There are many many blank lines in the program making it much harder
> to read. In future eliminate most or all of them.
>
> 5 - Most of us do not have the patience to count down 100 lines. In future
> flag the line with something like:
> room = map[next] < line 100
>
> 6 - quips = ["You've become a zombie and eat you pals. Douche."
>
>  "You've died and left your comrades to fend for themselves.
> Douche"
>  "Your whole group dies because of you. Douche."
>  "You've got terrible planning skills, and ruined the teams
> chances of survival. Douche."]
> quips is a list with one element, consisting of one string or 244
> characters.
> print quips[randint(0, len(quips)-1)]
> will always print the entire string.
> Perhaps you meant to put a comma at the end of each line?
>
> HTH and good luck.
>
> --
> Bob Gailer919-636-4239
> Chapel Hill NC
>
>


-- 
A computer without a Microsoft operating system is like a dog without
bricks tied to its head.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A Text Adventure Problem

2013-03-24 Thread Alan Gauld

On 24/03/13 21:09, John Bochicchio wrote:


4. I'm new to python, but I assume the error must have something to do
with not having a way for the program to move to the next area of the code.


Bob already gave you the clue.
Look atyou code for window.
What does it return?



--
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] A Text Adventure Problem

2013-03-24 Thread bob gailer

On 3/24/2013 3:41 PM, John Bochicchio wrote:

I've been trying to write a simple test text adventure

[snip]

Good first try! As you learn OOP and use of classes you will discover 
ways to improve and simplify coding.


Here's an example. It is far from perfect, but definitely worth a study. 
It will make text adventures easier to create. Note that this separates 
logic from data. Most room definitions have only data and the Room class 
has the common logic.


from sys import exit
from random import randint

class Room: # superclass of rooms
  actions = dict()
  def __init__(self):
self.prompt = ', '.join(self.actions.keys())
  def enter(self):
print self.enterMsg
if self.prompt:
  while True:
action = raw_input(self.prompt + ">").lower()
next = self.actions.get(action,None)
if next is None:
  print "Not a valid command"
else:
  print next[0]
  return next[1]
else:
  exit(1)

class Shack_front(Room):
  enterMsg = "The year is 2062, and the zombies have risen. You're not 
a doctor, and you have no training. You're just a guy trying to survive.\n"

  enterMsg += ".." * 8 + "\n"
  enterMsg += "You stand in front of a broken down shack, you here 
gurgles and screams from inside. There is a window to the side of the 
house "

  enterMsg += "that you can see through, or a door you can burst into.\n"
  enterMsg += ".." * 8 + "\n"
  actions = dict(
window = ("You silently walk over to the dirty window. You look 
inside to see a man held captive by 2 marauders. "
   "The marauders are armed with bats, and don't seem to know what 
they're doing. You have 1 9mm glock with 12 bullets.", 'window'),
door = ("You burst through the door with your shoulder. You see 
only one marauder. You shoot him in the chest and notice a man tied up "
"in a chair. You walk over to him but feel a sharp pain in the back 
of your head. You never saw the second marauder coming.", 'death'))


class Shack_window(Room):
  enterMsg = "Do you burst through the door or try to fire through the 
window at the marauders?"

  actions = dict(
window = ("You fire off three shots through the window. Two in the 
chest of the first marauder, one in the neck of the other. "
  "They fall to the ground, dead. You walk inside to see if 
the man is okay.", 'window'),
door = ("You burst through the door and fire two shots into the 
first marauder. You remember seeing two, so you turn around and "
"put one bullet through the head of the one behind you. You 
walk over to the man to see if he's okay.", 'death'))


class Death(Room):
  quips = ["You've become a zombie and eat you pals. Douche.",
   "You've died and left your comrades to fend for themselves. 
Douche",

   "Your whole group dies because of you. Douche.",
   "You've got terrible planning skills, and ruined the teams 
chances of survival. Douche."]

  enterMsg = quips[randint(0, len(quips)-1)]
  actions = dict()

rooms = dict(shack_front = Shack_front(), death = Death(), window = 
Shack_window())

next = 'shack_front'
while True:
  next = rooms[next].enter()

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


Re: [Tutor] A Text Adventure Problem

2013-03-24 Thread bob gailer

On 3/24/2013 5:09 PM, John Bochicchio wrote:
1. I'm using the terminal to run the code. Using the command - (cd 
python && python2 game1.py)

2. Using python 2.6 I believe.
3. I'm running Arch Linux at the moment.
4. I'm new to python, but I assume the error must have something to do 
with not having a way for the program to move to the next area of the 
code.
OK - what responses do you have to the rest of my questions and 
observations. Please respond thoroughly.


When you the the error copy and paste it directly from the terminal window.

Also in the future place your responses immediately after the item you 
are responding to rather than "top-posting".


Thank you for sending to the list as well as me.

What did you enter? I will bet is was 'window'.\


Questions:
1 - Did you think about what the error might mean?

Observations:

1 - The traceback does not match your code, so either you retyped
it or you are using some unusual way of running the program.

Compare
RUNNER (ROOMS, shack_front)
with
runner (ROOMS, 'shack_front')

2 - the error normally would look like KeyError: None rather than
keyerror= none

3 - The various room functions have at least one way out of them
with no return statement. The value returned in that case is None.

4 - There are many many blank lines in the program making it much
harder to read. In future eliminate most or all of them.

5 - Most of us do not have the patience to count down 100 lines.
In future flag the line with something like:
room = map[next] < line 100

6 - quips = ["You've become a zombie and eat you pals. Douche."

 "You've died and left your comrades to fend for
themselves. Douche"
 "Your whole group dies because of you. Douche."
 "You've got terrible planning skills, and ruined the
teams chances of survival. Douche."]
quips is a list with one element, consisting of one string or 244
characters.
print quips[randint(0, len(quips)-1)]
will always print the entire string.
Perhaps you meant to put a comma at the end of each line?



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


Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-24 Thread DoanVietTrungAtGmail
I read your help (thanks, Peter and Alan) and thought that relational
database technology didn't naturally map to my problem domain. Here, at
each simulation timestep each entity has a run-time variable number of
pointers to other entities. Representing each entity as a table seems
unwieldy to me.

So, I searched further and now write about what I've learnt, in case
someone with a similar problem finds this thread in future.

One possible set of solutions is the family of "NoSQL
databases".
Redis is one such DB, of "key-value" type, and in Pypi there is a package
called redis 2.7.2 . Another type
is "graph databases", and in Pypi there's a package called redis-graph
1.0built on top of
Redis.

I've also just installed Scipy because Scipy handles sparse
matrices.
My simulation has N entities, I'll try representing it as an NxN sparse
matrix, each row stores pointers in some sparse format to the rows it talks
to.

And then there's also NxN bitarray ,
where on each row a bit is 1 if this row points to this column, to save
space there's "compressed bitarray".  I also read about "Judy sparse
array", touted as fast and memory efficient, but last night I read the
author of the package PyJudy
writing
in 2009 that he hasn't maintained it for "a few years", that put me off.

Which one to use, I don't know yet. I am about to start experimenting with
Scipy sparse matrix.

Trung
==

On Thu, Mar 14, 2013 at 8:13 PM, Alan Gauld wrote:

> On 14/03/13 01:39, DoanVietTrungAtGmail wrote:
>
>> You don't. You create a second table to hold the list.
>> Then in the second table you include be reference back to the first.
>>
>> assuming I do it that way, how to deal with variable-length list? Most
>> lists have 10^3, but some can grow to perhaps 10^7 items. A fixed record
>> structure to fit the longest possible record would make the database
>> table sparse and, presumably, waste space.
>>
>
> I'm not sure what you mean here but the tables are not fixed size. Usually
> you are only limited by the size of your hard drive.
>
> To give an example if you have an object MyType with two of these list
> type attributes called foo and bar. We have two instances of MyType, A and
> B. A has 10 foos and 50 bars while B has 500 foos and 1000 bars.
>
> Create a table MyType and populate it with A and B
>
> Create a Table MyType_foo and populate it with 10 rows referencing A and
> 500 rows referencing B
>
> Create a table Mytype_bar and populate it with 50 rows referencing A and
> 1000 rows referencing bar
>
> Now to see all the foos for A use
>
> select value from foo where parent = A
>
> or for B use
>
> select value from foo whee parent = B
>
> and the same for bar...
>
> You can keep adding rows to foo or bar for as long as ypou like.
> Youb can add new MyType rows and then add more rows to MyType_foo and bar
> which reference thiose new MyTypes.
>
> There is no limit to how many items you add until your disk fills up!
>
>
>  An alternative I thought of was to use SQL Server fields for XML, or
>> varchar variable-length character strings containing 10^9 characters,
>> then to read the list I'd parse the XML or split the string into literal
>> integers then convert to int. I wanted to avoid this computation cost if
>> possible.
>>
>
> You can do this but you might as well just store everything in XML in a
> flat file. You lose the power of the database query language to
> search/filter the results and give yourself a huge
> development/test/maintenance task.
>
> The people who build databases are likely much better at this stuff that
> you or me. Use what they give you.
>
>
>
> --
> 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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Chapter 3 Projects

2013-03-24 Thread Mariel Jane Sanchez
Hi, I'm sort of new to Python. I'm taking Computer Science 10 and I'm now on 
Chapter 3. I don't really get how to do the first three projects.

Okay, so for the first project, I don't know how to input the ranges like 
0-999, 1000-, 1+ and even the negatives. Like when I run it on the 
shell, it doesn't have any errors whatsoever but it does another thing 
especially when I put 100, my typed phrase "Good Score" shows up when "Very 
Impressive" is the appropriate phrase to go with that score. And when I put in 
a negative score it says the same thing instead of saying it's an invalid 
score. How do I put those ranges so that the phrases match with it? 

I don't have the book nor the PDF at home, it's in school but I'm sure the 
second project is about flipping a coin 100 times and I have to show how many 
heads and tails where randomly flipped. My problem is that, I do get a random 
number for each sides of the coin but the number is either below or above 100. 
What am I doing wrong?

Lastly, the third project is doing the same thing as one of the demo codes. I 
have to make a guessing game that only gives the player 5 tries. I just don't 
understand how to end the loop when the user used up their 5 chances. When I 
run it and tried to guess the number, it's still the same as the demo code 
where I can guess as long as I want. What do I put to only have 5 chances? 
Also, how do I match the 2 phrases? For example, the player guessed the number 
within 5 attempts, the phrase that is congratulating the player should pop out 
and vise versa when the player exceeded his chances.

I worked on Chapter 3 review questions for the whole class, spent 2 class or 
less on the demos and the projects took me like 3 days and I'm still working on 
it. I do try to figure it out myself through trial and error but these projects 
got me. Thanks in advance.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Chapter 3 Projects

2013-03-24 Thread Dave Angel

On 03/24/2013 07:38 PM, Mariel Jane Sanchez wrote:

Hi, I'm sort of new to Python. I'm taking Computer Science 10 and I'm now on 
Chapter 3. I don't really get how to do the first three projects.

Okay, so for the first project, I don't know how to input the ranges like 0-999, 1000-, 1+ 
and even the negatives. Like when I run it on the shell, it doesn't have any errors whatsoever but 
it does another thing especially when I put 100, my typed phrase "Good Score" shows 
up when "Very Impressive" is the appropriate phrase to go with that score. And when I put 
in a negative score it says the same thing instead of saying it's an invalid score. How do I put 
those ranges so that the phrases match with it?



You can generate a range of numbers into a list with the range() 
function.  So if you want a list of all the ints between 0 and 999 
inclusive, you'd use

   mylist = range(0, 1000)

The rest of your paragrph was so unclear and incomplete that I didn't 
try to read the other paragraphs.


When you're able to post a real question, please do so.

Start by posting your email as text, not html.

Start with a problem statement (one, not three), a valid description of 
your environment, and some code that you tried. Since you claim to get 
different results when run from the shell, and from some other 
technique, I'll suggest you restrict yourself to only running from Linux 
terminal.  And include the full transcript from the Linux prompt forward.


Then describe how you ran it, what result you expected, and what you 
saw, including full traceback for any suggestion.  Be sure you use 
copy/paste, not retyping the code and messages.



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


[Tutor] (no subject)

2013-03-24 Thread Mandi Seger
Hello, everyone,

I am looking for suggestions on a beginner's book for learning Python. I
have a nursing background with basic science and math education. I have no
programming experience in any computer language.

I am currently enrolled in a Master's program for Geographic Information
Science and will be learning Python with an eye toward applying it in GIS
software programs such as ESRI's ArcMap.

I prefer to start with a book for ease of reference, and then move forward
with online resources.

Thank you for any input.

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


Re: [Tutor] Chapter 3 Projects

2013-03-24 Thread Alan Gauld

On 24/03/13 23:38, Mariel Jane Sanchez wrote:


thing especially when I put 100, my typed phrase "Good Score" shows
up when "Very Impressive" is the appropriate phrase to go with that
score. And when I put in a negative score it says the same thing instead
of saying it's an invalid score. How do I put those ranges so that the
phrases match with it?


Bear in mind that we have no idea what projects you are talking about. 
You might have the PDF at school but we don't even have that so you need 
to explain in detail what you are talking about.


When you say "input the ranges" what do you mean? Are you trying to read 
the range from a user? Or do you want to produce a range in your code? 
And do you need all of the numbers in the range? Or are you only testing 
against the max/min of the range? I can't tell from your description.



the second project is about flipping a coin 100 times and I have to show
how many heads and tails where randomly flipped. My problem is that, I
do get a random number for each sides of the coin but the number is
either below or above 100. What am I doing wrong?


Do you know how to repeat an action a known number of times?
If so the number of tails is the total minus the number of heads.
Can you collect or count the number of heads?


Lastly, the third project is doing the same thing as one of the demo
codes.


Without sight of the demo codes that means nothing to us.


 have to make a guessing game that only gives the player 5
tries. I just don't understand how to end the loop when the user used up
their 5 chances.


Do you know about while loops?

number_of_tries = 0
while number_of_tries < 5:
do your loop stuff here
number_of_tries = number_of_tries +1


When I run it and tried to guess the number, it's still
the same as the demo code where I can guess as long as I want. What do I
put to only have 5 chances? Also,



how do I match the 2 phrases? For
example, the player guessed the number within 5 attempts, the phrase
that is congratulating the player should pop out and vise versa when the
player exceeded his chances.


Do you know about if statements?
Also you can combine tests in your while loop using boolean (or logical) 
operators like and, or and not.

Does that help?

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] (no subject)

2013-03-24 Thread Alan Gauld

On 25/03/13 00:13, Mandi Seger wrote:


have a nursing background with basic science and math education. I have
no programming experience in any computer language.


I would try a library loan since such a book will be of limited value 
after you've finished it. There are a few that are suitable, including 
mine and Jeff Elkner's and a couple of others. It's hard to recommend
one without knowing how you learn... Mine and Jeff's both have online 
versions (although my book is now well behind the online version, I'm 
not sure about Jeff's)



I am currently enrolled in a Master's program for Geographic Information
Science and will be learning Python with an eye toward applying it in
GIS software programs such as ESRI's ArcMap.


There are libraries available to help with that and some of the folks on 
this list are actively involved. But that should wait till you at least 
have the basics down.



I prefer to start with a book for ease of reference, and then move
forward with online resources.


As well as the book you can also print out my V2 tutorial from the PDF 
file - or load it on an eReader if that works for you.


--
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] (no subject)

2013-03-24 Thread Robert Sjoblom
On 25 March 2013 01:13, Mandi Seger  wrote:
> Hello, everyone,
>
> I am looking for suggestions on a beginner's book for learning Python. I
> have a nursing background with basic science and math education. I have no
> programming experience in any computer language.

Head First Python or Head First Programming should fit the bill nicely
-- both books deal with Python, but in slightly different approaches.
Head First Python is much more focused on web applications and mobile
devices, where Head First Programming is more focused on building
Graphical interfaces (although simplified greatly). I would recommend
Head First Python over Programming, because Programming leaves out
classes (for one), and your stated background makes it sound like
you'll have more use, overall, from Head First Python. There are other
books out there, obviously, but Head First Python is the best one I've
come across.

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


Re: [Tutor] Fwd: Which databases allow lists as record fields?

2013-03-24 Thread Alan Gauld

On 24/03/13 22:36, DoanVietTrungAtGmail wrote:

I read your help (thanks, Peter and Alan) and thought that relational
database technology didn't naturally map to my problem domain. Here, at
each simulation timestep each entity has a run-time variable number of
pointers to other entities. Representing each entity as a table seems
unwieldy to me.


It really depends on your problem.
If you have a great many number of entity types then relational may not 
be the best solution. If you have a lot of entities of a few types then 
relational is a good match - thats what relational databases do best.


So the question is how many data types you need to deal with and the 
dependency graphs between the types. If there are many types all cross 
referencing each other then a non RDBMS may be a better fit. (although 
you can get round it in an RDBMS by modelling the type relationships as 
tables and then simply storing references to the type relations, but 
that's a bit of a forced solution i agree)



One possible set of solutions is the family of "NoSQL databases


There are a huge number of these ranging from single "big table" models 
to network and graph databases. There are also a myriad of recent "big 
data" stores too, with their own query languages, for example I've 
played with Hadoop.


Which one suits your problem depends on what you need to store and what 
you want to retrieve after you've stored 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] Beep sound

2013-03-24 Thread Phil

On 25/03/13 04:30, xDog Walker wrote:



Maybe something here:

http://code.activestate.com/search/recipes/#q=beep


Thanks xDog, yet another sound library (pyaudio) to play with.

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


Re: [Tutor] (no subject)

2013-03-24 Thread William Ray Wing
On Mar 24, 2013, at 8:13 PM, Mandi Seger  wrote:

> Hello, everyone,
> 
> I am looking for suggestions on a beginner's book for learning Python. I have 
> a nursing background with basic science and math education. I have no 
> programming experience in any computer language.
> 
> I am currently enrolled in a Master's program for Geographic Information 
> Science and will be learning Python with an eye toward applying it in GIS 
> software programs such as ESRI's ArcMap.
> 
> I prefer to start with a book for ease of reference, and then move forward 
> with online resources.
> 
> Thank you for any input.
> 
> Mandi Seger
> ___

Mandi,
I've looked at both Alan and Robert's replies.  They are both good and 
relevant - but I'm a bit concerned with your statement that: "I have no 
programming experience in any computer language."  In and of itself, this is 
NOT a problem, and with a nursing background and a math and science education, 
you are obviously more than smart enough.  What I'm focused on is the initial 
a-ha! moment when you suddenly see just what programming is all about - or more 
properly, how you examine a problem you want to solve and express that problem 
as a series of steps that the computer can carry out.  Most of the folks on 
this list experienced that a-ha moment so long ago, they've forgotten what it 
was like.  Different people get to that moment in different ways, and through 
different learning experiences.  But that moment IS critical.  Without it, you 
are writing programs by rote, and that will be frustrating and you won't get 
very far - let alone enjoy it, which you should.  With it, and after l
 earning your first computer language (and Python is an excellent choice), then 
learning other languages is trivial.  This is a VERY long winded and indirect 
recommendation to spend a couple of days in your university's book store.  It 
should have a sizable section on various computer languages and a selection of 
beginner books.  Look at the first chapter in several (and look at the first 
section of Alan's on-line tutorial, in which he talks about this subject).  
What you are looking for is a book that speaks to YOU, and gets you over that 
very first conceptual hump.
I might also suggest that as a first problem, pick something that is almost 
a pure exercise in simple mathematical logic - searching for prime numbers for 
example, or for perfect numbers.  Once you can break a problem like that down 
into simple declarative steps, you are on your way.

Welcome to the wonderful world of Python

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


Re: [Tutor] Beep sound

2013-03-24 Thread Phil

On 25/03/13 00:27, Bod Soutar wrote:


Your on the right track, the other thing I've seen is pcspkr being
blacklisted. Look in /etc/modprobe.d/blacklist.conf for a line like
'blacklist pcspkr' if it's there, remove it then modprobe or reboot
and it should be working again.


Thanks Bodsda,

I had a brief look through the black list files a couple of days ago and 
didn't find any mention of pcspkr. I've decided to drop this and simply 
use a sound module because they provide greater scope for experimentation.


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


Re: [Tutor] (no subject)

2013-03-24 Thread suhas bhairav
Python website provides you a whole set of resources catering to novices.

http://docs.python.org/2/tutorial/
Nick Parlante, a Stanford lecturer has created a wonderful tutorial on Python 
and you can find it in the below link:
https://developers.google.com/edu/python/
Google has free videos which teaches basic Python for people with no 
programming experience. Again, this is taught by Nick Parlante.
http://www.youtube.com/watch?v=tKTZoB2Vjuk
RegardsSuhas
From: suhasbhai...@hotmail.com
To: w...@mac.com; msege...@gmail.com
CC: tutor@python.org
Subject: RE: [Tutor] (no subject)
Date: Mon, 25 Mar 2013 10:43:21 +0530




I'm attaching a pdf which teaches you the basics of Python. This is the pdf 
that helped me learning python.
Apart from this, python website provides you a whole set of resources catering 
to novices.
http://docs.python.org/2/tutorial/
Nick Parlante, a Stanford lecturer has created a wonderful tutorial on Python 
and you can find it in the below link:
https://developers.google.com/edu/python/
Google has free videos which teaches basic Python for people with no 
programming experience. Again, this is taught by Nick Parlante.
http://www.youtube.com/watch?v=tKTZoB2Vjuk
RegardsSuhas

> From: w...@mac.com
> Date: Sun, 24 Mar 2013 21:38:17 -0400
> To: msege...@gmail.com
> CC: tutor@python.org; w...@mac.com
> Subject: Re: [Tutor] (no subject)
> 
> On Mar 24, 2013, at 8:13 PM, Mandi Seger  wrote:
> 
> > Hello, everyone,
> > 
> > I am looking for suggestions on a beginner's book for learning Python. I 
> > have a nursing background with basic science and math education. I have no 
> > programming experience in any computer language.
> > 
> > I am currently enrolled in a Master's program for Geographic Information 
> > Science and will be learning Python with an eye toward applying it in GIS 
> > software programs such as ESRI's ArcMap.
> > 
> > I prefer to start with a book for ease of reference, and then move forward 
> > with online resources.
> > 
> > Thank you for any input.
> > 
> > Mandi Seger
> > ___
> 
> Mandi,
> I've looked at both Alan and Robert's replies.  They are both good and 
> relevant - but I'm a bit concerned with your statement that: "I have no 
> programming experience in any computer language."  In and of itself, this is 
> NOT a problem, and with a nursing background and a math and science 
> education, you are obviously more than smart enough.  What I'm focused on is 
> the initial a-ha! moment when you suddenly see just what programming is all 
> about - or more properly, how you examine a problem you want to solve and 
> express that problem as a series of steps that the computer can carry out.  
> Most of the folks on this list experienced that a-ha moment so long ago, 
> they've forgotten what it was like.  Different people get to that moment in 
> different ways, and through different learning experiences.  But that moment 
> IS critical.  Without it, you are writing programs by rote, and that will be 
> frustrating and you won't get very far - let alone enjoy it, which you 
> should.  With it, and after l
>  earning your first computer language (and Python is an excellent choice), 
> then learning other languages is trivial.  This is a VERY long winded and 
> indirect recommendation to spend a couple of days in your university's book 
> store.  It should have a sizable section on various computer languages and a 
> selection of beginner books.  Look at the first chapter in several (and look 
> at the first section of Alan's on-line tutorial, in which he talks about this 
> subject).  What you are looking for is a book that speaks to YOU, and gets 
> you over that very first conceptual hump.
> I might also suggest that as a first problem, pick something that is 
> almost a pure exercise in simple mathematical logic - searching for prime 
> numbers for example, or for perfect numbers.  Once you can break a problem 
> like that down into simple declarative steps, you are on your way.
> 
> Welcome to the wonderful world of Python
> 
> -Bill
> ___
> 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