Robert Sokolewicz | 30 Oct 15:01 2014
Picon

passing named arguments through command line

I have a function with optional arguments x, y and I would like to pass y or z using a named variable through the command line. Inside a python script main(y=3) would work, but I have trouble passing y=3 as an argument in command line.

I have tried the following:

---- 
import sys

def main(x=1, y=2):
   print x
   print y

if __name__ == '__main__':
  main(*sys.argv[1:])

-----

from my terminal I get:

$ python script.py
1
2
$ python script.py y=3
y=3
2

whereas I would like the following to happen:
$ python script.py y=3
1
3

Is this doable in any convenient way? 

thanks in advance!

-Robert







_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
jarod_v6@libero.it | 30 Oct 09:32 2014
Picon

R: re question on array

Dear All,
Sorry for my bad presentation of my problem!!
I have this tipe of input:
A file with a long liste of gene ad the occurence for sample:

gene	Samples
FUS	SampleA
TP53	SampleA
ATF4	SampleB
ATF3	SampleC
ATF4	SampleD
FUS	SampleE
RORA	SampleE
RORA	SampleC

WHat I want to obtain is amtrix where I have the occurence for sample.
	SampleA	SampleB	SampleC	SampleD	SampleE
FUS	1	0	0	0	1
TP53	1	0	0	0	0
ATF4	0	1		1	0
ATF3	0	0	1	0	0
RORA	0	0	1	0	

In that way I count count the occurence in fast way!

At the moment I only able to do the list of the rownames and the sample names. 
Unfortunately I don't know how to create this matrix.
Cold you help me ?
Thanks for the patience and the help

>----Messaggio originale----
>Da: tutor-request <at> python.org
>Data: 30/10/2014 6.41
>A: <tutor <at> python.org>
>Ogg: Tutor Digest, Vol 128, Issue 74
>
>Send Tutor mailing list submissions to
>	tutor <at> python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	https://mail.python.org/mailman/listinfo/tutor
>or, via email, send a message with subject or body 'help' to
>	tutor-request <at> python.org
>
>You can reach the person managing the list at
>	tutor-owner <at> python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
>   1. Re: Would somebody kindly... (Steven D'Aprano)
>   2. Re: Would somebody kindly... (Dave Angel)
>   3. question  on array Operation (jarod_v6 <at> libero.it)
>   4. Re: question  on array Operation (Peter Otten)
>   5. Re: question  on array Operation (Alan Gauld)
>   6. Re: question  on array Operation (Steven D'Aprano)
>   7. Re: Would somebody kindly... (Clayton Kirkwood)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Wed, 29 Oct 2014 23:04:18 +1100
>From: Steven D'Aprano <steve <at> pearwood.info>
>To: tutor <at> python.org
>Subject: Re: [Tutor] Would somebody kindly...
>Message-ID: <20141029120417.GA26866 <at> ando.pearwood.info>
>Content-Type: text/plain; charset=us-ascii
>
>On Tue, Oct 28, 2014 at 04:13:19PM -0700, Clayton Kirkwood wrote:
>> Explain this double speak(>:
>> 
>> [pair for pair in values if key == pair[0]]
>
>Translated to a regular for-loop:
>
>result = []
>for pair in values:
>    if key == pair[0]:
>        result.append(pair)
>
>
>It iterates over the sequence `values`, extracting something called 
>`pair`. If the first item of `pair` == key, then the pair is placed in 
>the resulting list.
>
>py> values = [ ('a', 1), ('b', 2), ('a', 5), ('c', 7)]
>py> key = 'a'
>py> [pair for pair in values if key == pair[0]]
>[('a', 1), ('a', 5)]
>
>
>-- 
>Steven
>
>
>------------------------------
>
>Message: 2
>Date: Wed, 29 Oct 2014 08:29:56 -0400 (EDT)
>From: Dave Angel <davea <at> davea.name>
>To: tutor <at> python.org
>Subject: Re: [Tutor] Would somebody kindly...
>Message-ID: <m2qmd2$ji$1 <at> ger.gmane.org>
>Content-Type: text/plain; charset=UTF-8
>
>"Clayton Kirkwood" <crk <at> godblessthe.us> Wrote in message:
>> 
>> 
>> !-----Original Message-----
>> !From: Tutor [mailto:tutor-bounces+crk=godblessthe.us <at> python.org] On
>> !Behalf Of Dave Angel
>> !Sent: Tuesday, October 28, 2014 6:34 PM
>> !To: tutor <at> python.org
>> !Subject: Re: [Tutor] Would somebody kindly...
>> !
>> !
>> !>
>> ! Explain this double speak(>:
>> !>  [pair for pair in values if key == pair[0]]
>> !
>> !>  I understand the ?for pair in values?. I assume the first  ?pair?
>> !> creates the namespace
>> !
>> !The namespace question depends on the version of Python. Python  2.x
>> !does not do any scoping.
>> !
>> !But in version 3.x, the variable pair will go away.
>> !
>> !So please tell us the version you're asking about.
>> 
>> I am using 3.4.1.
>> 
>
>Have you somehow configured your email program to use exclamation
> points for quoting instead of the standard greater-than symbol?
> "!" instead of ">" ? If so, do you mind changing it
> back?
>
>In 3.4.1, let's consider the following code.
>
>thingie = 2
>mylist = [(2,55), "charlie", [2, "item2", 12]]
>x = [78 for item in mylist if item[0] == thingie]
>
>What will happen in the list comprehension, and what will be the
> final value of x ?
>
>First an anonymous list object will be created.  This eventually
> will be bound to x, but not till the comprehension is
> successfully completed. Next a locally scoped variable item is
> created.  This goes away at the end of the comprehension, 
> regardless of how we exit.
>
>Next the 0th value from mylist is bound to item. It happens to be
> a tuple, but not from anything the comprehension
> decides.
>Next the expression item [0] == thingie is evaluated.  If it's
> true, then the int 78 is appended to the anonymous
> list.
>
>Now the previous group of actions is repeated for the 1th value of
> mylist. So now item is a string, and the zeroth character of the
> string is compared with the int 2. Not equal, so 72 doesn't get
> appended.
>
>Similarly for the 2th item. The first element of that list is
> equal to 2, so another 72 is appended.
>
>Now the anonymous list is bound to x.
>
>print (x)
>[72, 72]
>
>
>
>-- 
>DaveA
>
>
>
>------------------------------
>
>Message: 3
>Date: Wed, 29 Oct 2014 17:08:28 +0100 (CET)
>From: "jarod_v6 <at> libero.it" <jarod_v6 <at> libero.it>
>To: tutor <at> python.org
>Subject: [Tutor] question  on array Operation
>Message-ID:
>	<700633221.1075021414598908994.JavaMail.defaultUser <at> defaultHost>
>Content-Type: text/plain; charset="utf-8"
>
>Dear All,
>
>I have a long matrix where I have the samples (1to n) and then I have (1to j )
elements.
>I would like to count how many times  each j element are present on each 
samples.
>
>So the question is which is the best algoritm for obtain the results. The 
result I want is a table like that.
>
>
>
>A,B,D,E,F
>AA,1,0,1,0
>BB1,1,1,1
>CC0,0,1,0
>DD01,0,1,0
>
>
>Do you have any suggestion on how to do this?  only using a loop like:
>
>A is a list with some names A=[AA,BB,ZZ,TT,NN]
>
>if AA in A:
>    print 1
>else :
>    print 0
>
>thanks in advance for any help
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20141029/ca8bdc9c/attachment-0001.html>
>
>------------------------------
>
>Message: 4
>Date: Wed, 29 Oct 2014 17:49:06 +0100
>From: Peter Otten <__peter__ <at> web.de>
>To: tutor <at> python.org
>Subject: Re: [Tutor] question  on array Operation
>Message-ID: <m2r5q2$ibm$1 <at> ger.gmane.org>
>Content-Type: text/plain; charset="ISO-8859-1"
>
>jarod_v6 <at> libero.it wrote:
>
>> Dear All,
>> 
>> I have a long matrix where I have the samples (1to n) and then I have (1to
>> j )elements.
>> I would like to count how many times  each j element are present on each
>> samples.
>> 
>> So the question is which is the best algoritm for obtain the results. The
>> result I want is a table like that.
>> 
>> 
>> 
>> A,B,D,E,F
>> AA,1,0,1,0
>> BB1,1,1,1
>> CC0,0,1,0
>> DD01,0,1,0
>> 
>> 
>> Do you have any suggestion on how to do this?  only using a loop like:
>> 
>> A is a list with some names A=[AA,BB,ZZ,TT,NN]
>> 
>> if AA in A:
>>     print 1
>> else :
>>     print 0
>> 
>> thanks in advance for any help
>
>I'm sorry I have no idea what you are trying to do.
>
>I can't believe that this is your "best effort" to explain the problem, so I 
>won't bother to guess.
>
>
>
>------------------------------
>
>Message: 5
>Date: Wed, 29 Oct 2014 17:29:12 +0000
>From: Alan Gauld <alan.gauld <at> btinternet.com>
>To: tutor <at> python.org
>Subject: Re: [Tutor] question  on array Operation
>Message-ID: <m2r858$2d5$1 <at> ger.gmane.org>
>Content-Type: text/plain; charset=windows-1252; format=flowed
>
>On 29/10/14 16:08, jarod_v6 <at> libero.it wrote:
>
>> I have a long matrix where I have the samples (1to n) and then I have
>> (1to j )elements.
>> I would like to count how many times  each j element are present on each
>> samples.
>
>That probably makes sense to you but it doesn't to me.
>Lets assuyme you have n=10 and j=5.
>That would suggest you have a 10x5 matrix of values?
>
>Now what do you mean by 'each j' element? The last one in the row?
>
>So for this small example:
>
>1,2,3,4,5,   -> count = 1 - there is only one 5
>1,2,1,2,1,   -> count = 3 - there are 3 ones
>A,3,B,2,A    -> count = 2 - there are 2 As
>
>Is that what you want?
>
>> So the question is which is the best algoritm for obtain the results.
>> The result I want is a table like that.
>>
>> A,B,D,E,F
>> AA,1,0,1,0
>> BB1,1,1,1
>> CC0,0,1,0
>> DD01,0,1,0
>
>That doesn';t senm to match your description above. You will
>need to show us both input and output data before we can
>understand the transformation you are looking for.
>
>> Do you have any suggestion on how to do this?
>
>Not until I understand what you want.
>
>
>-- 
>Alan G
>Author of the Learn to Program web site
>http://www.alan-g.me.uk/
>http://www.flickr.com/photos/alangauldphotos
>
>
>
>------------------------------
>
>Message: 6
>Date: Thu, 30 Oct 2014 09:06:29 +1100
>From: Steven D'Aprano <steve <at> pearwood.info>
>To: tutor <at> python.org
>Subject: Re: [Tutor] question  on array Operation
>Message-ID: <20141029220629.GB26866 <at> ando.pearwood.info>
>Content-Type: text/plain; charset=us-ascii
>
>On Wed, Oct 29, 2014 at 05:08:28PM +0100, jarod_v6 <at> libero.it wrote:
>> Dear All,
>> 
>> I have a long matrix where I have the samples (1to n) and then I have (1to 
j )elements.
>> I would like to count how many times  each j element are present on each 
samples.
>
>Jarod, looking at your email address, I am guessing that English is not 
>your native language. I'm afraid that I cannot understand what you are 
>trying to do. Please show a *simple* example.
>
>I will make a *guess* that you have something like this:
>
>matrix = [ # three samples of seven values each
>           [2, 4, 6, 8, 6, 9, 5], 
>           [3, 5, 1, 7, 9, 8, 8], 
>           [1, 2, 0, 6, 6, 2, 1],
>           ]
>
>and then you want to count how many each element [0, 1, 2, 3, 4, 5, 6, 
>7, 8, 9] appear in each sample:
>
>
>from collections import Counter
>for i, sample in enumerate(matrix, 1):
>    c = Counter(sample)
>    print("Sample %d" % i)
>    print(c)
>    
>
>which gives me:
>
>Sample 1
>Counter({6: 2, 2: 1, 4: 1, 5: 1, 8: 1, 9: 1})
>Sample 2
>Counter({8: 2, 1: 1, 3: 1, 5: 1, 7: 1, 9: 1})
>Sample 3
>Counter({1: 2, 2: 2, 6: 2, 0: 1})
>
>
>Does that help?
>
>If not, you have to explain what you need better.
>
>
>-- 
>Steven
>
>
>------------------------------
>
>Message: 7
>Date: Wed, 29 Oct 2014 22:39:53 -0700
>From: "Clayton Kirkwood" <crk <at> godblessthe.us>
>To: <tutor <at> python.org>
>Subject: Re: [Tutor] Would somebody kindly...
>Message-ID: <06b801cff403$eed61340$cc8239c0$ <at> us>
>Content-Type: text/plain;	charset="UTF-8"
>
>
>
>>-----Original Message-----
>>From: Tutor [mailto:tutor-bounces+crk=godblessthe.us <at> python.org] On
>>Behalf Of Dave Angel
>>Sent: Wednesday, October 29, 2014 5:30 AM
>>To: tutor <at> python.org
>>Subject: Re: [Tutor] Would somebody kindly...
>>
>>"Clayton Kirkwood" <crk <at> godblessthe.us> Wrote in message:
>>>
>>>
>>> !-----Original Message-----
>>> !From: Tutor [mailto:tutor-bounces+crk=godblessthe.us <at> python.org] On
>>> !Behalf Of Dave Angel
>>> !Sent: Tuesday, October 28, 2014 6:34 PM
>>> !To: tutor <at> python.org
>>> !Subject: Re: [Tutor] Would somebody kindly...
>>> !
>>> !
>>> !>
>>> ! Explain this double speak(>:
>>> !>  [pair for pair in values if key == pair[0]] !
>>> !>  I understand the ?for pair in values?. I assume the first  ?pair?
>>> !> creates the namespace
>>> !
>>> !The namespace question depends on the version of Python. Python  2.x
>>> !does not do any scoping.
>>> !
>>> !But in version 3.x, the variable pair will go away.
>>> !
>>> !So please tell us the version you're asking about.
>>>
>>> I am using 3.4.1.
>>>
>>
>>Have you somehow configured your email program to use exclamation
>>points for quoting instead of the standard greater-than symbol?
>> "!" instead of ">" ? If so, do you mind changing it  back?
>>
>>In 3.4.1, let's consider the following code.
>>
>>thingie = 2
>>mylist = [(2,55), "charlie", [2, "item2", 12]] x = [78 for item in
>>mylist if item[0] == thingie]
>>
>>What will happen in the list comprehension, and what will be the  final
>>value of x ?
>>
>>First an anonymous list object will be created.  This eventually  will
>>be bound to x, but not till the comprehension is  successfully
>>completed. Next a locally scoped variable item is  created.  This goes
>>away at the end of the comprehension,  regardless of how we exit.
>>
>>Next the 0th value from mylist is bound to item. It happens to be  a
>>tuple, but not from anything the comprehension  decides.
>>Next the expression item [0] == thingie is evaluated.  If it's  true,
>>then the int 78 is appended to the anonymous  list.
>>
>>Now the previous group of actions is repeated for the 1th value of
>>mylist. So now item is a string, and the zeroth character of the  string
>>is compared with the int 2. Not equal, so 72 doesn't get  appended.
>>
>>Similarly for the 2th item. The first element of that list is  equal to
>>2, so another 72 is appended.
>>
>>Now the anonymous list is bound to x.
>>
>>print (x)
>>[72, 72]
>
>So, in this case, the assignment to x is external. Often I don't see an 
external assignment, but there is an item in the first position within the 
comprehension. You don't have that here. When you have [item for item in [list] 
if item[0] == key], after the iteration completes does item equal the matched 
entities or does it have the original item? I understand that if we had x = 
[dsfasdfasdf] x will be a list (never a tuple?) with the matches, but what 
happens to the first item?
>
>This is from a previous email--
>When I run:
>values = [ ('a', 1), ('b', 2), ('a', 5), ('c', 7)]
>key = 'a'
>pair=[]
>[pair for pair in values if key == pair[0]]
>print(pair)
>
>I get [].
>
>When I run:
>values = [ ('a', 1), ('b', 2), ('a', 5), ('c', 7)]
>key = 'a'
>pair=[]
>x=[pair for pair in values if key == pair[0]]
>print(x)
>
>I get [('a', 1), ('a', 5)]
>
>So, what does that first pair do? I see and have used the first 
comprehension.
>
>
>Clayton
>
>
>>
>>
>>
>>--
>>DaveA
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor <at> python.org
>>To unsubscribe or change subscription options:
>>https://mail.python.org/mailman/listinfo/tutor
>
>
>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>Tutor maillist  -  Tutor <at> python.org
>https://mail.python.org/mailman/listinfo/tutor
>
>
>------------------------------
>
>End of Tutor Digest, Vol 128, Issue 74
>**************************************
>

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

jarod_v6@libero.it | 29 Oct 17:08 2014
Picon

question on array Operation

Dear All,

I have a long matrix where I have the samples (1to n) and then I have (1to j )elements.
I would like to count how many times  each j element are present on each samples.

So the question is which is the best algoritm for obtain the results. The result I want is a table like that.



A,B,D,E,F
AA,1,0,1,0
BB1,1,1,1
CC0,0,1,0
DD01,0,1,0


Do you have any suggestion on how to do this?  only using a loop like:

A is a list with some names A=[AA,BB,ZZ,TT,NN]

if AA in A:
    print 1
else :
    print 0

thanks in advance for any help
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Clayton Kirkwood | 29 Oct 00:13 2014
Picon

Would somebody kindly...

Explain this double speak(>:

[pair for pair in values if key == pair[0]]

 

I understand the ‘for pair in values’. I assume the first ‘pair’ creates the namespace (although I am not sure how Python knows it’s a tuple yet). I think the outer [] make the line a comprehension ( If so, I don’t seem to get how/why a comprehension works), and probably make the line either a tuple or list. The comprehension seems to act as a subroutine or macro( yes I know those two words are meaningless in Python). I definitely am missing the full meaning of the if statement. The example comes courtesy of Alan.

 

Thanks,

 

Clayton

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Adam Jensen | 27 Oct 19:24 2014
Picon

subprocess.Popen basics

Hi, I'm exploring Popen today and I seem to be having some trouble
deciphering the [documentation][1].

[1]: docs.python.org/3/library/subprocess.html#popen-constructor

In this example (below), I expect to start a shell script as a separate
process, send a line of text through a pipe (to the shell script's
stdin) then read the shell script's response (a line of text) from
another pipe (attached to the shell script's stdout).

---------------------------------------------------------
#!/usr/bin/env python3.4

import subprocess as sp

parrot = sp.Popen(['./parrot.sh'],
        stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE,
        universal_newlines=True, start_new_session=True)

parrot.stdin.write('Pushing up daisies.\n')
print('Parrot said: ', parrot.stdout.readline())
parrot.kill()
---------------------------------------------------------

Where "parrot.sh" is:
---------------------------------------------------------
#!/bin/bash
while true
do
    read foo
    echo "Squawk: $foo"
done
---------------------------------------------------------

It hangs at the print statement and, from the sound of the fans in the
computer, I suspect it spirals off into an infinite loop somewhere /
somehow. Does anyone have any ideas about what it is that I might be
misunderstanding?

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Caroline H | 26 Oct 23:15 2014
Picon

Python Questions Help

Hi Python Tutor, 

I'm having a lot of trouble with this python problem and I'm wondering if you can help me.
"Given the lists, lst1 and lst2 , create a new sorted list consisting of all the elements of lst1 that also appears in lst2 . For example, if lst1 is [4, 3, 2, 6, 2] and lst2 is [1, 2, 4], then the new list would be [2, 2, 4]. Note that duplicate elements in lst1 that appear in lst2 are also duplicated in the new list. Associate the new list with the variable new_list , and don't forget to sort the new list."

The code I wrote almost works, it just needs to be able to add a number more than once in the third list. 
For example, 
lst1 = [2,5,6,7,2] 
lst2 = [2,4] 

it comes up with new_list = [2] when I need it to come up with new_list = [2,2] 

The code I have so far is: 

new_list = [] 
i = 0 
j = 0 
if len(lst1)<=len(lst2): 
    for i in range(len(lst1)): 
        if lst1[i] in lst2: 
            new_list.append(lst1[i]) 
else: 
    for j in range(len(lst2)): 
        if lst2[j] in lst1: 
            new_list.append(lst2[j])

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Malik Brahimi | 26 Oct 21:25 2014
Picon

User Input with Multiple Lines

So I am working with input that is pasted from a PDF file, and I was wondering if there is any way I can do so without the program terminating abruptly because of the newlines. I know that multiple lines of input can be achieved via a loop with string concatenation, but this is not what I'm looking for. Remember, I am trying to directly cut and paste a PDF paragraph with newlines into a console program without an unexpected exit. Take a look at the following PDF for an example: Example PDF
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Dominik George | 26 Oct 18:18 2014
Picon

Re: Auto-response for your message to the "Tutor" mailing list

Hi,

Am 26. Oktober 2014 13:20:13 MEZ, schrieb tutor-bounces <at> python.org:
>Your message for tutor <at> python.org, the Python programming tutor list,
>has been received and is being delivered.  This automated response is
>sent to those of you new to the Tutor list, to point out a few
>resources that can help with answering your own questions, or improve
>the chances of getting a useful answer from the other subscribers.

why is it I get this messages repeatedly despite having been reading and writing on the list for over a year now?

Cheers,
Nik
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

William Becerra | 26 Oct 10:01 2014
Picon

Differentiating vowels from consonants

Hello, I'm new to programming
Running Python 2.7.8 on Windows 8 OS
 
Here there is an example of the for loop with a Cheerleader
program but the program is not able to print grammatically correct.


word = raw_input("Who do you go for? ") for letter in word: call = "Gimme a " + letter + "!" print call print letter + "!" print "What does that spell?" print word + "!"
I tried changing the code so that  the program
can recognize vowels from consonants and write the correct article (a or an)
here is my code.

word = raw_input("Who do You Support: ")
vowels = ('a', 'e', 'i', 'o', 'u')

for letter in word:
    if letter == vowels:
        call = 'Give me an ' + letter + '!'
        print call
        print letter + '!'
    else :
        call = 'Give me a ' + letter + '!'
        print call
        print letter + '!'
        
print 'What does that say'
print word + '!!'


My code also isn't able to recognise vowels.
For example if i write Manchester as the raw_input
i get :
give me a M
give me a a
etc.
I would like it to say
give me a M
give an a

So here is my question. What is wrong with my code and how can I change it to get the result I want.
Thank You




_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Crush | 26 Oct 14:12 2014
Picon

Re: Python GPIO Code Help Needed

Could this work?

/usr/bin/env python

import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

pin_list = ['GPIO.input(23)', 'GPIO.input(23)', 'GPIO.input(23)']

for item in pin_list:
   if item == false:
   os.system('mpg321 -g 95 a.mp3')

Bo 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Bill Bright | 26 Oct 02:05 2014
Picon

Python GPIO Code Help Needed

I have been working on a piece of code that I got from another tutorial. The code polls the GPIO pins on a
Raspberry Pi. When it detects a switch being flipped, it plays a corresponding audio file. My problem is,
if the switch remains flipped, the audio repeats again and again. What I would like to do is when a switch is
flipped have the audio play, then have the code pause until the switch is returned to normal (not repeating
the audio), and then return to the while loop to poll for the next switch flip. I am apparently not smart
enough to figure out the correct code. I really need some help with this and I would appreciate any assistance.

Here is the code I'm working with.

#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
while True:
        if ( GPIO.input(23) == False ):
                os.system('mpg321 -g 95 a.mp3')
        if ( GPIO.input(24) == False ):
                os.system('mpg321 -g 95 b.mp3')
        if ( GPIO.input(25)== False ):
                os.system('mpg321 -g 95 c.mp3')
        sleep(1.1);
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Gmane