Translating Matlab code to Python
<p>I need to translate chunks of matlab code into Python. My code seems to be 'unreachable' though. Any idea why this is happening? 
Also: am I doing it right? I'm a real newbie.</p>

<p>Matlab code:</p>

<pre><code>function Dir = getScriptDir()
    fullPath = mfilename('fullpath');
    [Dir, ~,~] = fileparts(fullPath);
end

function [list,listSize] = getFileList(Dir)
    DirResult = dir( Dir );
    list = DirResult(~[DirResult.isdir]); % select files
    listSize = size(list);
end
</code></pre>

<p>My Python code: </p>

<pre><code>def Dir = getScriptDir():
    return os.path.dirname(os.path.realpath(__file__)
def getFileList(Dir):
    list = os.listdir(Dir)
    listSize = len(list)
    getFileList() = [list, listSize]
</code></pre>

<p>Your syntax is incorrect. If I'm reading this correctly, you're trying to get the names of the files in the same directory as the script and print the number of files in that list.</p>

<hr>

<p>Here's an example of how you might do this (based on the program you gave):</p>

<pre><code>import os

def getFileList(directory = os.path.dirname(os.path.realpath(__file__))):
    list = os.listdir(directory)
    listSize = len(list)
    return [list, listSize]

print(getFileList())
</code></pre>

<hr>

<p>Output example:</p>

<pre><code>[['program.py', 'data', 'syntax.py'], 3]
</code></pre>

python matlab function translation