simple pattern matching in python
<p>I am trying to write a basic interpreter in python.
So, I am at that point where I am trying to declare whether a string entered in command prompt is a method or variable type.</p>

<p>So not trying any fancy stuff..</p>

<pre><code>s="12345" #variable
s ="foo()" method
s = "foo(1234)" method
</code></pre>

<p>What is a robust way to do this (for example.. robust for whitespaces ... throw error if syntax is not proper)</p>

<p>My code is pretty straightforward</p>

<pre><code>s = s.strip()

params=   s[s.find("(") + 1:s.find(")")] # find the params..
</code></pre>

<p>The above command works in case two and case three but for case 1.. it gives weird results.. </p>
