Python Forum
Pyhton code help from head first with python - 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: Pyhton code help from head first with python (/thread-27440.html)



Pyhton code help from head first with python - Shaikat_99 - Jun-07-2020

I am a beginner learning python . i am following the book "head first python ". In that in chapter of creating a webapp , i am facing a problem as i have install modules but as the step in book mentions the process to import the module
"vsearch " from "search4letters" .
But i am unable to find it as its showing module not find.


Book code
from flask import Flask
from vsearch import search4letters
app = Flask(__name__)
@app.route('/')
def hello() -> str:
 return 'Hello world from Flask!'
@app.route('/search4')
def do_search() -> str:
 return str(search4letters('life, the universe, and everything', 'eiru,!'))
app.run()
my code
from flask import Flask
from vsearch import search4letters
app = Flask(__name__)
@app.route('/')

def hello() -> str:
    return 'hello world from flask dumbo !'

@app.route('/search4')

def do_search()->str :
    return str('life the universe and evrthing','eiru/')
app.run()
but still i am getting a error in importing the module.


RE: Pyhton code help from head first with python - scidam - Jun-07-2020

I tried to install vsearch using pip and it does not work neither under Windows, nor Linux. It seems that vsearch module is incorrectly deployed (has incorrect setup file). However, you can download the archive with vsearch module directly, from here. Unzip it, and put vsearch.py file into your project's folder. vsearch.py is very simple,its content is just a few lines of code:

def search4vowels(phrase: str) -> set:
    """Return any vowels found in a supplied phrase."""
    vowels = set('aeiou')
    return vowels.intersection(set(phrase))


def search4letters(phrase: str, letters: str='aeiou') -> set:
    """Return a set of the 'letters' found in 'phrase'."""
    return set(letters).intersection(set(phrase))
So, you can put these lines to your file instead of importing search4letters function.


RE: Pyhton code help from head first with python - buran - Jun-07-2020

(Jun-07-2020, 06:34 AM)Shaikat_99 Wrote: book mentions the process to import the module
"vsearch " from "search4letters"
this would mean
from search4letters import vsearch
looking at https://github.com/ScubaSteve11/search4letters
I guess search4letters is a folder they have made you create? On other hand in webapp.py they import search4letters from vsearch


RE: Pyhton code help from head first with python - snippsat - Jun-07-2020

Use my vvsearch Wink
In the book i guess before creating a web-app chapter,
there is chapter about making a module(vsearch) so it can be installed bye pip.
If you have have done this chapter then import should work.
from flask import Flask
from vsearch import search4letters # The module maked before in book
If not done this chapter can just use code as @scidam explain.
scidam Wrote:and put vsearch.py file into your project's folder. vsearch.py is very simple