Python Forum
python 3 from command line - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: python 3 from command line (/thread-24726.html)



python 3 from command line - Dixon - Mar-01-2020

Can't figure out why I cannot run these two small scripts from the command line. Pasted below is a copy of the results I get. It did work at a point in time, but I am doing something wrong that I haven't been able to dope out.

C:\Users\Dixon\mymodules>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> search4vowels('abcde')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'search4vowels' is not defined
>>> quit()

C:\Users\Dixon\mymodules>type search4vowels
The system cannot find the file specified.

C:\Users\Dixon\mymodules>dir
Volume in drive C is Windows
Volume Serial Number is 7478-065A

Directory of C:\Users\Dixon\mymodules

02/14/2020 05:40 PM <DIR> .
02/14/2020 05:40 PM <DIR> ..
02/14/2020 05:23 PM 308 vsearch.py
1 File(s) 308 bytes
2 Dir(s) 452,053,323,776 bytes free

C:\Users\Dixon\mymodules>type vsearch.py
(# -*- coding: utf-8 -*-
"""
Created on Fri Feb 14 17:13:51 2020

@author: -
"""

def search4vowels(phrase:str) -> set:
vowels = set('aeiou')
return vowels.intersection(set(phrase))

def search4letters(phrase: str, letters: str) -> set:
return set(letters).intersection(set(phrase))

C:\Users\Dixon\mymodules>

Here's what happens when I 'import' the module vsearch.py

C:\Users\Dixon\mymodules>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vsearch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Dixon\mymodules\vsearch.py", line 8
def search4vowels(phrase:str) -> set:
^
SyntaxError: invalid syntax
>>>


RE: python 3 from command line - snippsat - Mar-01-2020

Remember this Thread Dixon? and use code tag.
So there did i post full working setup,that takes it also one step further as also making a wheel.
The vvsearch module will also of course working stand alone,it's from the book you did read Head first Python.
I did a called it vvsearch,so you should avoid conflict if already make vsearch.
# vvsearch.py
def search4vowels(phrase: str) -> set:
    vowels = set('aeiou')
    return vowels.intersection(set(phrase))

def search4letters(phrase: str, letters: str) -> set:
    return set(letters).intersection(set(phrase))

if __name__ == '__main__':
    print(search4letters('hitch-hiker', 'aeiou'))
    print(search4letters('galaxy', 'xyz'))
    print(search4letters('life, the universe, and everything', 'o'))
Usage if import:
C:\code
λ ptpython
>>> import vvsearch

>>> vvsearch.search4vowels('abcde')
{'e', 'a'}
>>> vvsearch.search4letters('hello', 'aeiou')
{'e', 'o'}