#๐Ÿ”’ Need help coding my first grep

40 messages ยท Page 1 of 1 (latest)

high walrus
#

I've been told to code a grep as my next python project but have no clue where to start

bold cloudBOT
#

@high walrus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wooden oar
#

What does grep do?

#

(i know what grep does, but we're going to talk about it)

high walrus
#

Or just searches for patterns in general

wooden oar
#

first it needs to be told what to look for, how does that happen?

high walrus
wooden oar
high walrus
#

can i tell you using what knowledge i have of the re library?

wooden oar
#

sure, but we're not at re yet, you said it needs to get input from the user.

high walrus
#

okay so

#

the user tells the grep command what to search through, then it recieves an input of what to search, through a function

wooden oar
#

let's be very specific about the actual UI of this program. What does it look like when a user uses it?

wooden oar
#

ok, and the pattern to search for is specified on the command line.

high walrus
#

yes

#

like this

#

$ echo 'hello\nworld' | grep hello

wooden oar
#

do you know how to read things from the command line?

high walrus
wooden oar
high walrus
#

i dont know grep at all

#

i was just told to code a grep in python

wooden oar
#

forget grep. Write a program called xyz. When you run xyz hello, it prints You asked me to search for 'hello'

high walrus
#

okay ill do it quickly

wooden oar
#

wait: we were making a list of things it needs to do.

#

the first thing is, get the pattern from the command line.

high walrus
#

okay lets do that

#

how do i do that

wooden oar
#

where did you see the word findstr?

#

i'm going to need to go

high walrus
#

you use it to search text files on windows

high walrus
wooden oar
#

who told you to write grep? How are you learning to program?

bold cloudBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.