omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    SimpleRSSreader

    Pythonista
    share
    6
    8
    5723
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • beer2011
      beer2011 last edited by

      Hello, all.
      Already some programs , I tried to add a little only , the function .
      If you are interested , please try .
      For those of the original author , thank you .

      SimpleRSSReader
      https://gist.github.com/beer2011/fcc4aaeec2a0f489b8fa

      Phuket2 1 Reply Last reply Reply Quote 1
      • Phuket2
        Phuket2 @beer2011 last edited by Phuket2

        @beer2011 , thanks for sharing. Nice to read through the code for ideas. One thing I spotted, that appears it's a potential problem.
        feeds=[]

        class FeedListController(object):
        	
        	def __init__(self, feeds=[]):
        		self.feeds = feeds
        		self.table = None
        

        From what I have been reading a few days ago, dynamic objects should not be in the param list as there are only ever evaluated once. Can produce some strange bugs. Maybe I am wrong, maybe only a problem for functions.
        From what I remember they say better to do feeds = None

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by ccc

          The problem and a potential solution:

          def default_args_broken(my_list=[]):
              my_list.append(len(my_list))
              print(my_list)
          
          def default_args_working(my_list=None):
              my_list = my_list or []
              my_list.append(len(my_list))
              print(my_list)
          
          default_args_broken()   # [0]
          default_args_broken()   # [0, 1]
          default_args_broken()   # [0, 1, 2]
          
          default_args_working()  # [0]
          default_args_working()  # [0]
          default_args_working()  # [0]
          
          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by omz

            @ccc

            my_list or [] can have unintended side effects too because an empty list is evaluated as False. Consider this:

            def append_something(my_list=None):
                my_list = my_list or []
                my_list.append(len(my_list))
            
            foo = []
            append_something(foo)
            print foo # => [] -- huh?
            
            bar = [0]
            append_something(bar)
            print bar # => [0, 1]
            

            (Granted, the example is a bit contrived.)

            1 Reply Last reply Reply Quote 0
            • dgelessus
              dgelessus last edited by

              And that is why you should write the None check using ternary if-else instead of or:

              my_list = [] if my_list is None else my_list
              
              1 Reply Last reply Reply Quote 1
              • techteej
                techteej last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • beer2011
                  beer2011 last edited by

                  The reply to everyone who, thank you.
                  In fact, I, programming is amateur.
                  (For even English, but it is the same.sorry. ^^;; )
                  And to understand what has been taught, it is likely to take some time.
                  Again, thank you.

                  Phuket2 1 Reply Last reply Reply Quote 0
                  • Phuket2
                    Phuket2 @beer2011 last edited by

                    @beer2011 , understand. I am also learning. Still brought up a good discussion. I hadn't been aware of this proble. A tricky one.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors