Python: AttributeError: 'NoneType' object has no attribute 'rfind'
<p>I am trying to determine the file extension using os.path.splitext</p>

<p>here is my code:</p>

<pre><code>for emailid in msgs:
    typ, s = mail.fetch(emailid, "(RFC822)")
    m = email.message_from_string(s[0][1])
    result = re.findall(pattern,str)
    if result:     
        for part in m.walk():
            filename = part.get_filename()
            if filename:
                extension = os.path.splitext(fileName)
                if extension[1][1:] == 'csv':      
                    ### Process into a dataframe
                    df = pd.read_csv(StringIO(filename))
</code></pre>

<p>here is the error readout from IPython:</p>

<pre><code>#### Begin error Message #####

    AttributeError                            Traceback (most recent call last)
&lt;ipython-input-83-71fabd157c43&gt; in &lt;module&gt;()
     40             if filename:
     41                 print type(filename)
---&gt; 42                 extension = os.path.splitext(fileName)
     43                 if extension[1][1:] == 'csv':
     44                     ### Process into a dataframe

C:\Anaconda2\lib\ntpath.pyc in splitext(p)
    198 
    199 def splitext(p):
--&gt; 200     return genericpath._splitext(p, sep, altsep, extsep)
    201 splitext.__doc__ = genericpath._splitext.__doc__
    202 

C:\Anaconda2\lib\genericpath.pyc in _splitext(p, sep, altsep, extsep)
     97     leading dots.  Returns "(root, ext)"; ext may be empty."""
     98 
---&gt; 99     sepIndex = p.rfind(sep)
    100     if altsep:
    101         altsepIndex = p.rfind(altsep)

AttributeError: 'NoneType' object has no attribute 'rfind'

#### End Error message #####
</code></pre>

<p>NoneType should mean I am not passing anything, when I print type(filename) i get: </p>

<p>how do I pass the file so I can determine extension and then create a dataframe? do I need to save to disk</p>

<p>this will be for a parsing script that gets regularly scheduled csv'ed emailed to it, hence the regex to determine which rule to follow.</p>