Python Forum
Pyhton code help from head first with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyhton code help from head first with python
#1
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.
Reply
#2
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.
Reply
#3
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Vlookup function in Pyhton antozas 1 590 Oct-02-2023, 04:16 AM
Last Post: vikraman
  numpy.array has no attribute head Led_Zeppelin 1 1,193 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Cannot get output for df.head() Led_Zeppelin 0 1,020 Jun-28-2022, 02:15 PM
Last Post: Led_Zeppelin
  Reading Multiple text Files in pyhton Fatim 1 1,885 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Pandas: .(head) Can I specify a range in head? eeps24 6 3,575 May-11-2020, 04:27 PM
Last Post: eeps24
  start interactive pyhton shell with pre-loaded custom modules Viktor 2 2,142 Apr-09-2020, 08:25 AM
Last Post: Viktor
  PYHTON not opening files profficial 11 13,358 Feb-15-2020, 09:06 AM
Last Post: bharathendra
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,107 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  Pyhton Coding Help Needed (very small error) friduk 2 2,407 Oct-23-2019, 08:41 AM
Last Post: Gribouillis
  Cant get my head round the algorithm hshivaraj 1 2,265 Apr-09-2019, 10:38 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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