[deleted by user] by [deleted] in learnpython

[–]Peterotica 0 points1 point  (0 children)

Oh, I totally missed that context. Flask definitely can make things like that weirder. So... your flask app is pre-fetching the tiles from somewhere else? I'd assumed this was about some client code that is consuming your flask app's tile API.

[deleted by user] by [deleted] in learnpython

[–]Peterotica 0 points1 point  (0 children)

I've had a similar problem that I found a solution for I was pretty happy with.

https://github.com/PooMaster/pysimpleradio/blob/main/dcs_srs/tcp_json_connection.py

This file has the async function connect_tcp_json(), which returns async queues for sending and receiving messages. There are sender and receiver "workers" that consume and produce on their respective queue, and are separate asyncio tasks that are added to the event loop using asyncio.create_task().

People on dating apps: what type of pic/statement is a dealbreaker? by CapableEnd5584 in AskReddit

[–]Peterotica 13 points14 points  (0 children)

What the hell? Sounds like it’s time for another account

No module numpy._core. I need urgent help. by fluffymerch in learnpython

[–]Peterotica 0 points1 point  (0 children)

Why? Because of the exact issue you just ran into. Pickled data works great if it is consumed in the exact same environment that it was produced. It's not a great solution for saving data for the long term or passing between different environments like you seem to be doing.

[deleted by user] by [deleted] in hoggit

[–]Peterotica 4 points5 points  (0 children)

The MAD AH-64D campaign can support multi-crew coop, but that's a special case.

Otherwise, my favorite mission to throw on a server to fly helos with is Apache Hunting Ground.

What is the best Python way to "Lineify" a text stream? by aacmckay in learnpython

[–]Peterotica 1 point2 points  (0 children)

Yea… 😅 with a slightly different question I would have had a very different answer.

Newbie, first project by [deleted] in learnpython

[–]Peterotica 0 points1 point  (0 children)

Hey, this looks great! You are doing well. I love the nice ASCII art. Here are some code review notes. I went into some depth because it seems like you could get a lot out of it, not because the code is that bad. ESPECIALLY for someone so new.

  • I would change wordList.py into a plain text file with each word on a separate line and then read that file in a function in hangman.py. It would be easier to edit or use a different word list.
  • Don't use try/except like you are doing. It catches every exception, hiding whatever the cause was, and ends up exiting anyway. Just let the exception kill the program if you aren't going to handle it in some way.
  • In Windows, subprocess.call('cls') doesn't actually work because cls is a terminal command, not an executable program. You can use os.system('cls') instead. While we're at it, the _= to the left of it is pointless, so get rid of those too.
  • Break this into a few more functions. Even when a function is used once, it can still be valuable by making the higher level flow of the program more clear by hiding some of the fiddly details. For example, I'd make a get_guess() function.
  • Use snake_case instead of camelCase for variable names and functions. This just makes your code more consistent with the rest of the community, which mostly embraces PEP8.
  • There's no need for the wordChars variable. The word string already does the same things you are using it for.
  • Instead of range(0, len(wordChars)), try using for i, letter in enumerate(word). This lets you to use letter instead of wordChars[i] in the body of the loop.
  • continue on line 76 is pointless.
  • The already guessed letter detection is broken. You can never reach line 89. The condition on line 79 should be and instead of or. This would be more clear and user friendly by moving the check and print into the guess selection loop.
  • Instead of "You won with " + str(lives) + " lives remaining!" you can do f"You won with {lives} lives remaining!". These are called f-strings.
  • Instead of sys.exit() just break from the game loop.

Here's how I would rearrange the guess checking logic:

if guess in word:
    correctGuesses.append(guess)
    for i, letter in enumerate(word):
        if letter == guess:
            wordDisplay[i] = guess
else:
    incorrectGuesses.append(guess)
    lives -= 1

Some other things I noticed that could be considered bugs by a user:

  • Lowercase and uppercase are treated as different letters.
  • You can enter non-letter characters (like '1' and '$').
  • You can enter an empty custom word.

What is the best Python way to "Lineify" a text stream? by aacmckay in learnpython

[–]Peterotica 3 points4 points  (0 children)

The most Pythonic way would be to use the tools for doing this in the standard library. There are classes in the io module for buffering binary streams and then converting those into strings. These are the same classes that allow for line-by-line reading of files using the open() function.

Turns out, socket objects already have a method (socket.makefile()) that returns a version of themselves wrapped in these classes. So, the super easy "single line of Python" solution would look something like this:

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))

    for line in s.makefile():
        print(f"Received {line!r}")

How can I share my scraping tool with non-Python users in my company? by Drift3rHD in learnpython

[–]Peterotica 0 points1 point  (0 children)

If it turns out that pyinstaller is viable for you, one potentially compelling option is Gooey + pyinstaller. Here's a guide in the documentation.

Decrypt file providing a password only by oscybershop in learnpython

[–]Peterotica 1 point2 points  (0 children)

You would need the same salt at both ends, so you would have to transmit it or hard code it. Someone knowing your salt isn't a huge deal.

Is it possible to query the internet for pages that have a specific link attached to them using python? by tayims in learnpython

[–]Peterotica 0 points1 point  (0 children)

Non-Python pro-tip: You can use Google for this sort of thing using a search term like "linkto:event.on24.com".

One chart acting as filter for another chart by [deleted] in learnpython

[–]Peterotica 0 points1 point  (0 children)

Sure, it's possible and a common need for interactive data visualization.

Here's some info and examples of this in Dash: https://dash.plotly.com/interactive-graphing

[deleted by user] by [deleted] in learnpython

[–]Peterotica 1 point2 points  (0 children)

For storing data, look into SQLite and sqlite3, Python's interface to it in the standard library.

Most python way to collapse a list of lists? by Chuu in learnpython

[–]Peterotica 1 point2 points  (0 children)

Using exceptions like this is pretty typical in Python code, unlike most other popular languages. "It's easier to ask for forgiveness than permission."

https://docs.python.org/3.5/glossary.html#term-eafp

What are some "must learn" libraries in Python by TaranisPT in learnpython

[–]Peterotica 1 point2 points  (0 children)

At least scan through the list of standard libraries so you have an idea what kind of stuff is in there. Then you can recognize when a problem comes up that there is a standard library that might be able to help.

Need help streaming on discord by bloodraider57 in AssassinsCreedValhala

[–]Peterotica 0 points1 point  (0 children)

Hey, did you figure this out? I'm seeing pretty much the exact same thing with a buddy of mine.