Re: PSA: A python script to clone your phone exactly, over Wi-Fi or USB

Maria Sophia <[email protected]>
Newsgroups gmane.comp.python.general
Organization BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID <[email protected]>
Lawrence D¢Oliveiro wrote:
> You do this sequence of execute/fetch calls 4 times in your script.

Now, turning to your second set of suggestions regarding a more Pythonic
coding philosophy and perhaps making use of the db_iter helper: ... 

It's a good idea where using a generator function to wrap repetitive
execute() and fetching patterns certainly keeps code DRY (Don't Repeat
Yourself) & I can see the advantage of putting the lookup in the loop.

It will take a while for me to fully digest your helpful suggestions, as I
noted in the prior response that I suffer from lack of SQL experience.

In fact, in the original thread, I originally tried to disassemble the
homescreen using SQL queries in DB Browser for SQLite v3.13.1 but gave up.
 Message-ID: <[email protected]>

If I were to adapt your db_iter concept while keeping parameterized queries
safe, I'd probably modify it to accept a parameters tuple like this:

Python
def db_iter(conn, cmd, params=(), mapfn=lambda x: x):
    """Executes cmd with parameters and yields mapped results."""
    for item in conn.cursor().execute(cmd, params):
        yield mapfn(item)

That way, I get the clean generator loop style you recommended and maintain
strict parameter safety. Thanks again for taking the time to review the
code and thank you for offering suggestions such as that refactoring idea.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.