Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-20 Thread Alan Gauld

On 20/12/11 01:33, Stayvoid wrote:


I want to have a possibility to import modules from the folder, which
is not included in the load path.


The code and error below has nothing to do with importing modules or the 
PYTHONPATH value.



module.py
-
def testfunc(name):
   file = open(name)
   return len(file.readlines())

if __name__ == "__main__":
   print testfunc(module.py)


This is simply opening the file module.py as any other file.
It does not invoke Pythons import mechanism.


Code listing (shell):
python /Users/Username/pythonmodules/module.py

NameError: name 'module.py' is not defined



Please post the full error text not a summary.
But in this case it isc complaining about the favct that you have not 
put quotes around the filename so it thinks module.py is a variable, but 
when it looks for it, it is not defined.


BTW To set PYTHONPATH in a MacOSX environment you have to edit your 
.profile or .bash_profile (I can never remember which!) and add a line like


export PYTHONPATH=/path/to/your/modules:/another/module/path/here

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] Beginner Exercise: Why Didn't I Break It?

2011-12-20 Thread Homme, James
Hi,
Please don't give me the answer. Please tell me where to read to find out.

So far, the data types this little book has talked about are strings and 
numbers.

The book is here. http://learnpythonthehardway.org/book/

I cut out the parts of the program I definitely understand to focus on this 
part.

This exercise is a practice exercise that talks about functions. The 
instructions were to try to break the file and make it not run, so I decided to 
try to call the below function with one argument instead of three. I'm trying 
to explain to myself why it didn't break. I have comments in here for what I 
think is going on.

# This function takes one argument.
# It returns three items.

def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates

start_point = 1

# It returns three things in parentheses, which, I guess is one group of 
things. I thought it would complain.
stuff = secret_formula(start_point)
print stuff
# This is three items, according to me. It makes three separate variables, that 
we print out below.
beans, jars, crates = secret_formula(start_point)

print "We have %d beans, %d jars, and %d crates." % (beans, jars, crates)

Thanks.

Jim
Jim Homme,
Usability Services,
Phone: 412-544-1810.




This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner Exercise: Why Didn't I Break It?

2011-12-20 Thread Jerry Hill
On Tue, Dec 20, 2011 at 12:31 PM, Homme, James  wrote:
> So far, the data types this little book has talked about are strings and 
> numbers.
...
> return jelly_beans, jars, crates
...
> # It returns three things in parentheses, which, I guess is one group of 
> things. I thought it would complain.


You book may not have talked about it yet, but there is a third data
type involved here, a tuple.  The secret_formula() function doesn't
actually return three separate things.  It returns a single object
that contains a sequence of three other objects.  In this case, it
specifically returns a tuple (rather than a list or other sequence
type).

Take a look here
http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
for more about tuples in particular, and the rest of that page for an
overview of sequence types in general.

>beans, jars, crates = secret_formula(start_point)

This line performs what python calls "sequence unpacking" (sometimes
also called "tuple unpacking").  That's described in the same link I
referenced above.

Hopefully that gives you a few places to read more without explaining
the whole thing.

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


Re: [Tutor] Beginner Exercise: Why Didn't I Break It?

2011-12-20 Thread Homme, James
Hi Jerry,
Thank you. This reminds me of single dimension arrays in VBScript. Note that I 
said Reminds. I'm trying to pretend I don't know about other languages, so I 
can give myself less learning stress.

thanks.

Jim

-Original Message-
From: tutor-bounces+james.homme=highmark@python.org 
[mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Jerry 
Hill
Sent: Tuesday, December 20, 2011 1:00 PM
To: tutor@python.org
Subject: Re: [Tutor] Beginner Exercise: Why Didn't I Break It?

On Tue, Dec 20, 2011 at 12:31 PM, Homme, James  wrote:
> So far, the data types this little book has talked about are strings and 
> numbers.
...
> return jelly_beans, jars, crates
...
> # It returns three things in parentheses, which, I guess is one group of 
> things. I thought it would complain.


You book may not have talked about it yet, but there is a third data
type involved here, a tuple.  The secret_formula() function doesn't
actually return three separate things.  It returns a single object
that contains a sequence of three other objects.  In this case, it
specifically returns a tuple (rather than a list or other sequence
type).

Take a look here
http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
for more about tuples in particular, and the rest of that page for an
overview of sequence types in general.

>beans, jars, crates = secret_formula(start_point)

This line performs what python calls "sequence unpacking" (sometimes
also called "tuple unpacking").  That's described in the same link I
referenced above.

Hopefully that gives you a few places to read more without explaining
the whole thing.

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



This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Threads and Signals

2011-12-20 Thread Andrew Heagle
Hi,

I am testing out some stuff with threads and signals. This is just a prototype 
of how I want to incorporate it into my main script.

I figured out how to "catch" signals for SIGUSR1 to output what all the thread 
children are "working" on. The problem I have is if in terminalA I run my 
script, and in terminalB I do `kill -SIGUSR1 $pid` the output from the script 
shows up on terminalA. How can I get the output to show up in terminalB? The 
reason I ask is because the script will be running in a loop forever doing 
something, so I would like to be able to "query it". 

I attached my test script in case that helps, so feel free to critique my code 
at the same time, if you like as I just starting learning Python recently.

Thanks,
Andrew
# -*- coding: utf-8 -*-
#!/usr/bin/python

import threading
import Queue
import time
import random
import signal

queue = Queue.Queue()
ctlqueue = Queue.Queue()

class myt(threading.Thread):
def __init__(self, name, run_event, queue, ctlqueue):
threading.Thread.__init__(self, name = name)
self.run_event = run_event
self.queue = queue
self.ctlqueue = ctlqueue
def run(self):
msg = ""
while self.run_event:
st = int(str(random.random() * 5)[0]) + 1

try: msg = self.ctlqueue.get(False)
except Queue.Empty:
pass
if msg == "Shutdown" or self.queue.empty():
print "I see shutdowns"
self.run_event = False
continue

try: u = self.queue.get(True, 5)
except Queue.Empty  : pass
self.username = u
time.sleep(st)
try: msg = self.queue.get(False)
except Queue.Empty:
pass

else:
print "Thread %s exiting..." % self.name
self._Thread__stop()

def printusers(signal, stack):
for x in range(threading.activeCount()):
try:
pt = threading.enumerate()[x]
print "Parent asks children for status: Child replies: I am %s and I have %s" % (pt.name, pt.username)
except: pass

def main():
users = ["kkanya", "Beatsascewsad", "manaligmd", "snotrastaeh", "rojskegalb", "autoluwix", "chopekwazi", "batemanfrg", "Gleddyea", "falcucciyk", "previnguiml", "Totenseekd", "Nawezinr", "cinematoriasj",]

for u in users:
queue.put(u)

run_event = threading.Event()
for x in range(2):
tname = "PThread-%s" % x
t = myt(tname, run_event, queue, ctlqueue)
t.daemon = True
t.start()

while threading.activeCount() > 1:
try:
time.sleep(1)

except KeyboardInterrupt as e:
print "\nExiting... Please wait for threads to clean up...  "
for x in range(2):
ctlqueue.put("Shutdown")

if __name__ == '__main__':
signal.signal(signal.SIGUSR1, printusers)
try:
print "Starting PThread..."
main()
except KeyboardInterrupt as e:
print "later"___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner Exercise: Why Didn't I Break It?

2011-12-20 Thread Alan Gauld

On 20/12/11 18:10, Homme, James wrote:

Hi Jerry,
Thank you. This reminds me of single dimension arrays in VBScript.


You are absolutely right, tuples are like read-only arrays in VB.
We have writeable arrays in python too but we call them something
else :-)

BTW The list prefers bottom posting to top posting so in future
if you can add your comments after the relevant mail content
that will be greatly appreciated. :-)

--
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] request for guidance on goertzel algorithm for DTMF detection

2011-12-20 Thread Ganesh Borse
Dear Tutors,

I was studyin the two python implementations of geortzel algo for DTMF
detection:

http://www.black-aura.com/blog/2011/12/10/python-implementation-of-the-goertzel-algorithm-dtmf-decoding/
.

http://johnetherton.com/projects/pys60-dtmf-detector/

However, I found that both of these have limited functionality in terms of
frequency ranges and when it comes to .wav files with more noise.

Can you please help to guide me if you are aware of any other better
implementations of goertzel algo in python? Or which can be the best
mailing list for the queries regarding DTMF decoding/ goertzel alogs?

Thanks for your help.

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


Re: [Tutor] A few Python Mysteries

2011-12-20 Thread Wayne Watson
I changed Python25 to Python27, and rebooted.  I got the same two dll 
msgs again.


On 12/19/2011 7:33 PM, Wayne Watson wrote:
It became apparent during the other part of this thread that I had not 
uninstalled Python 2.7, as I thought I had.  As pointed out in the 
PATH discussion (James R.), the last item in the system variable PATH 
was Python25. I would think then changing it to Python27 might Python 
rolling again.




--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- "The Date" The mystery unfolds.

Web Page:


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


Re: [Tutor] A few Python Mysteries

2011-12-20 Thread James Reynolds
On Tue, Dec 20, 2011 at 9:32 PM, Wayne Watson
wrote:

> I changed Python25 to Python27, and rebooted.  I got the same two dll msgs
> again.
>
>
> On 12/19/2011 7:33 PM, Wayne Watson wrote:
>
>> It became apparent during the other part of this thread that I had not
>> uninstalled Python 2.7, as I thought I had.  As pointed out in the PATH
>> discussion (James R.), the last item in the system variable PATH was
>> Python25. I would think then changing it to Python27 might Python rolling
>> again.
>>
>>
> --
>   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
> (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
> CE 1955 October 20 07:53:32.6 UT
>-- "The Date" The mystery unfolds.
>
>Web 
> Page:http://www.speckledwithstars.net/>
> >
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>

Did you also verify that Python is installed at C:\Python27 and not some
other place?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor