title: How do I tell Python an object is a list?
body: <p>I felt real close finalizing a function I had been working on for some time, but there was a problem. I can't seem to be able to communicate with Python that an object I'm passing through a function is a list object.</p>
  
  <p>This is my function: <code>log(a, b, c)</code></p>
  
  <p>My log function is supposed to take a string 'b', and append it to a list 'a' that may or may not exist already, and then take the -1 index of list 'a' (which is the b string) and append it to list 'c'.</p>
  
  <p>I needed mostly more automation out of this function. At the moment, without this function, on a daily basis I have to always code and define 'a' first, then add 'b' to it, append a bunch of stuff, and add a['b'] to c! Way too much work! I need the function to automate that entire process. This is the code I used in my attempt to implement my function:</p>
  
  <pre><code>def log(a, b, c):
      try:a
      except NameError: a= None
      if a is None:
                  a=list()
                  a.append(b)
                  c.append(a[-1])
  
      else:
                  a.append(b)
                  c.append(a[-1])
  </code></pre>
  
  <p>When I try to use the function, in a case where 'a' is non-existent, Python keeps telling me:</p>
  
  <blockquote>
    <p>NameError: Name 'a' is not defined</p>
  </blockquote>
  
  <p>And that is without quotation marks. If I put quotation marks around the 'a' object, it then tells me:</p>
  
  <blockquote>
    <p>AttributeError: 'str' object has no attribute 'append'</p>
  </blockquote>
  
  <p>basically telling me that Python doesn't understand that the 'a' object is supposed to be a list, not a string (why is talking to computers so hard?).</p>
  
  <p>My function only works if object 'a' ('c' is not a concern because you can consider those a set of lists that are a constant in the program, 'a' is more of a variable because I need a new list everyday) is defined before the runtime of the log().</p>
  
  <p>How can I pass an object through my function, and have Python accept that if it does not exist, it should be a new list object?</p>
  
  <p>People are asking for more code. Like I said in the comments, this is just the test of a function which will be eventually integrated into an existing script, where any value of ‘c’ exists already, but here’s what happens at the prompt:</p>
  
  <pre><code>&gt;&gt;&gt;log(“March_25_2018”,{“Log_1”:”Test PMIC tonight.”},Project_Logs)
  </code></pre>
  
  <p><em>I’m forced to put March_25_2018 in quotation if it has not been defined before the run of the function. This is the problem; Python handles ‘a’ as a string and not a list. ‘c’ is not a concern, because in the final program, c is always defined anyway.</em></p>
  
  <pre><code>    &gt;&gt;&gt;Tracback (most recent call last):
     File “&lt;pyshell#73&gt;”, line 1, in &lt;module&gt;
       log(“March_25_2018”,{“Log_1”:”Test PMIC tonight.”},”Project_Logs”)
     File “User_Space/.py”, line 10, in log
     a.append(b)
     AttributeError: ‘str’ object has no attribute ‘append’.
  </code></pre>