How to use a wildcard in python to check for any extension
<p>I am trying to check the input to see if it has any extension here is the code I used:</p>

<pre><code>filename=input()
if "." in filename:
    print ("There is")
</code></pre>

<p>However this will return "there is" even if the input is ends with just a full stop.<br>
  Is there any way to check if the input has any letters after the "."?
  I can't specify what the extension should be (as it is up to the user), just that there should be an extension. </p>

<p>An easy option would be to check for "." in <code>filename</code> with the last character removed:</p>

<pre><code>if len(filename)&gt;1 and "." in filename[:-1]:
    print("there is")
</code></pre>

<p>This would allow "file..", which may or may not be what you want.  Another idea would be, to split <code>filename</code> at every "." and check that you get at least two parts, the last of which is non-empty:</p>

<pre><code>parts = filename.split(".")
if len(parts) &gt; 1 and parts[-1]:
    print("there is")
</code></pre>

<p>This will not allow "file..", but will allow "file.,".  If you want to only allow extensions which consist of letters, you should probably use regular expressions.  For example, you could try the following:</p>

<pre><code>import re
m = re.match('[a-z]*\.[a-z]+', filename)
if m:
    print("there is")
</code></pre>

<p>This will allow "file.txt", but not "a.b.c".  Regular expressions are very flexible and this approach can be extended to check for quite specific name formats.</p>

python wildcard