Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #46  
Old January 8th, 2013, 01:52 PM
Erents Erents is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 Erents User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 30 sec
Reputation Power: 0

Hi, I am a bit of a newbie and have a simple problem that I cannot solve so I have come here to get some help from the experts.

I am trying to count the number of gpio inputs per second. I have the code to count the number of inputs and I can count a second using time.time etc. I just cannot figure this out the code required to count inputs per second.



Any help would be appreciated!

Thanks,

Martin.

Reply With Quote
  #47  
Old January 30th, 2013, 03:21 PM
Lucantrop Lucantrop is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 21 Lucantrop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 15 m 41 sec
Reputation Power: 0
Hey, Martin, for starters, I'm pretty sure that this is not the right topic for asking questions, but since it's out here, why not answer it anyway - The math behind your problem is pretty simple as in total_inputs/total_time = inputs_per_second.
To get the inputs and time you need to:
Code:
import time

start_time = time.time()
total_inputs = 0

# insert the code for inputs with total_inputs += 1 for every input
# probably best in a while loop

total_time = time.time() - start_time

def gpio_per_sec(inputs, total_time):
    input_per_sec = inputs/time
    print inputs_per_sec # optional

gpio_per_sec(inputs, total_time)
And that should do it.

Reply With Quote
  #48  
Old February 20th, 2013, 01:25 PM
PythonNewb PythonNewb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 15 PythonNewb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 19 sec
Reputation Power: 0
Thanks for the tips guys!

Reply With Quote
  #49  
Old March 12th, 2013, 03:17 AM
aleque aleque is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 9 aleque User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 7 sec
Reputation Power: 0
Awesome links. Thanks!

Can someone please recommend me a good Python book? It must cover the most important parts of Python and appeal to a beginner like me. There are lots of books out there and it is hard to chose, so I trust the suggestions on this forum

Reply With Quote
  #50  
Old May 7th, 2013, 06:43 AM
johnmacklen johnmacklen is offline
Temporarily Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 11 johnmacklen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 33 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
There are many tips and tricks you can learn in Python:

There are many tips and tricks you can learn in Python:

Strings:
*Triple quotes are an easy way to define a string with both single and double quotes.
*String concatenation is expensive. Use percent formatting and str.join() for concatenation:

(but don't worry about this unless your resulting string is more than 500-1000 characters long)
Code:
print "Spam" + " eggs" + " and" + " spam"               # DON'T DO THIS
print " ".join(["Spam","eggs","and","spam"])            # Much faster/more
                                                        # common Python idiom
print "%s %s %s %s" % ("Spam", "eggs", "and", "spam")   # Also a pythonic way of
                                                        # doing it - very fast



Module choice:
*cPickle is a faster, C written module for pickle. cPickle is used to serialize python program. Other modules have C implementations as well, cStringIO for the StringIO module, and cProfile for the profile module.
Code:
import cPickle # You may want to import it as P for convenience.


*These can even fall back to the slower pure-python version if they fail to import.

Code:
try:
  import cPickle as pickle
except ImportError:
  import pickle



Some more tips & tricks on next posts...
please keep in touch ...

Thank You...!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tips, tricks, inspiration, etc

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap