Page 4 of 4 First ... 234
  • Jump to page:
    #46
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep 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.
  2. #47
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    3
    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.
  4. #48
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0
    Thanks for the tips guys!
  6. #49
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep 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
  8. #50
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    13
    Rep 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...!!!
  10. #51
  11. No Profile Picture
    Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    7
    Rep Power
    0

    Re:Tips, tricks, inspiration, etc


    Hopefully this thread will be able to help any Pythoner. Whether it be a complete beginner or a very advanced expert.
  12. #52
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Smile


    your post about python program really helpful to the viewers,hopefully they are conscious about python excitation.
  14. #53
  15. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    620
    Rep Power
    65
    List comprehensions work differently with Python2 and Python3 ...
    python Code:
    ''' cheese_list1.py
    print the items in a list in sorted order using list comprehension
    tested with Python33 (Python27 gives error)
    '''
     
    cheese_list = [
    'Feta', 'Limburger', 'Camembert', 'Roquefort', 'Edam',
    'Romadur', 'Liptauer', 'Dubliner', 'Gouda', 'Gorgonzola',
    'Jarlsberg', 'Golka', 'Garrotxa', 'Swiss', 'Quesillo',
    'Emmentaler', 'Appenzeller', 'Raclette', 'Asiago', 'Zuvi',
    'Ricotta', 'Mozzarella', 'Munster', 'Parmesan']
     
    [print(cheese) for cheese in sorted(cheese_list)]
     
    ''' result ...
    Appenzeller
    Asiago
    Camembert
    Dubliner
    Edam
    Emmentaler
    Feta
    Garrotxa
    Golka
    Gorgonzola
    Gouda
    Jarlsberg
    Limburger
    Liptauer
    Mozzarella
    Munster
    Parmesan
    Quesillo
    Raclette
    Ricotta
    Romadur
    Roquefort
    Swiss
    Zuvi
    '''
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  16. #54
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0
    Wow I found so many useful tips on this thread, thanks!
  18. #55
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    3
    Originally Posted by Dietrich
    List comprehensions work differently with Python2 and Python3 ...
    python Code:
    ''' cheese_list1.py
    print the items in a list in sorted order using list comprehension
    tested with Python33 (Python27 gives error)
    '''
     
    cheese_list = [
    'Feta', 'Limburger', 'Camembert', 'Roquefort', 'Edam',
    'Romadur', 'Liptauer', 'Dubliner', 'Gouda', 'Gorgonzola',
    'Jarlsberg', 'Golka', 'Garrotxa', 'Swiss', 'Quesillo',
    'Emmentaler', 'Appenzeller', 'Raclette', 'Asiago', 'Zuvi',
    'Ricotta', 'Mozzarella', 'Munster', 'Parmesan']
     
    [print(cheese) for cheese in sorted(cheese_list)]
     
    ''' result ...
    Appenzeller
    Asiago
    Camembert
    Dubliner
    Edam
    Emmentaler
    Feta
    Garrotxa
    Golka
    Gorgonzola
    Gouda
    Jarlsberg
    Limburger
    Liptauer
    Mozzarella
    Munster
    Parmesan
    Quesillo
    Raclette
    Ricotta
    Romadur
    Roquefort
    Swiss
    Zuvi
    '''
    And for anyone wondering, this happens because print was made into a function in python3, while in python2 it is a statement.
    To do the same in python27:
    python Code:
    list = ['b', 'a', 'e', 'c', 'd']
    print '\n'.join([i for i in sorted(list)])
     
    '''
    result:
    a
    b
    c
    d
    e
    '''
  20. #56
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0
    Many thanks for the tips guys!
  22. #57
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Location
    nigeria
    Posts
    1
    Rep Power
    0

    help new to python lang


    hello just joined this site really need help on how to be a python Lang guru
Page 4 of 4 First ... 234
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo