Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3 from command line
#1
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
>>>
Reply
#2
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'}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Command line argument issue space issue mg24 5 1,280 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  accept command line argument mg24 5 1,240 Sep-27-2022, 05:58 PM
Last Post: snippsat
  multi-line CMD in one-line python kucingkembar 5 3,861 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  Accessing varying command line arguements Rakshan 3 2,008 Jul-28-2021, 03:18 PM
Last Post: snippsat
  How to input & output parameters from command line argument shantanu97 1 2,506 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Passing List of Objects in Command Line Python usman 7 3,087 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  Taking Multiple Command Line Argument Input bwdu 6 3,928 Mar-29-2020, 05:52 PM
Last Post: buran
  Running linux command line apps... dbrdh 0 1,620 Jan-30-2020, 01:14 PM
Last Post: dbrdh
  Python convert multi line into single line formatted string karthidec 2 9,274 Dec-23-2019, 12:46 PM
Last Post: karthidec
  command line input (arg parse) and data exchange Simba 7 4,245 Dec-06-2019, 11:58 PM
Last Post: Simba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020