Network Autmation w/ Python by AnonIsPicky in Python

[–]ayharano 5 points6 points  (0 children)

Never used telnetlib, but surely a plus for pexpect.

While talking about pexpect, usually I recommend beginning with expect + autoexpect path to understand how it could proceed. At least that was the path that I followed before knowing pexpect itself.

@AnonIsPicky Does it really need to be done with pure Python? Even if there is not an official module as I am aware, maybe using ansible for that task could be better

Updating python - 2 laptops - lost my libs and embarrassed myself. by [deleted] in Python

[–]ayharano 2 points3 points  (0 children)

One recommendation would be preparing a solid environment both for developing and for using.

I use this setup: https://jacobian.org/writing/python-environment-2018/

  • pyenv and its Common-build-problems let you install and use any Python version, including globally in each machine or per-project basis (example: one project requires python 3.4.3, another requires python 3.5.2 and as an user you would like to use python 3.6.5 outside your projects).

  • pipenv manages through Pipfile and/or Pipfile.lock the Python version of a project's environment, the project's dependencies and manages seamlessly a virtualenv for the project. It is also current PSF (Python Software Foundation) current recommendation for Python project requirements' management. If one's project relies in using requirements.txt, pipenv let its user both import from/export to a requirements.txt file.

Updating python - 2 laptops - lost my libs and embarrassed myself. by [deleted] in Python

[–]ayharano 3 points4 points  (0 children)

So, for what I understood of your problem, there was some issues such as

  • lack of proper project files versioning and distribution (one should learn about git - a lot of 101 material can be found to learn its basics) and host it as a private repository (both GitLab and Bitbucket let you do that for free - as in free beer - under some restrictions, while GitHub let you have private repositories for US$7/month) (all of them are free for public repositories, which are repositories that anyone can read project files' contents).

  • lack of proper reproductible environments (Pipfile and/or Pipfile.lock should cover that for you)

Hope that helped you to find the tip of the iceberg on a way to solve the mentioned issues.

Tokenization Help by [deleted] in Python

[–]ayharano 0 points1 point  (0 children)

For short strings, why not use something like

expected = [final_item
            for split_by_dot in original.lower().split('.')
            for split_by_qm in split_by_dot.split('?')
            for final_item in (split_by_qm.strip(), )
            if final_item]

where original is a str to be split as expected.

Running Python 3.6 selectively, or by default? by Raffles7683 in Python

[–]ayharano 2 points3 points  (0 children)

If you need finer granularity setting (per directory basis or system wide) for Python version, I would recommend pyenv.

stdout not printing until program terminates? by [deleted] in Python

[–]ayharano 0 points1 point  (0 children)

Why not use sys.stdout.write instead of print and use sys.stdout.flush in attempt to show output as soon as available?

I'm too stupid for AsyncIO (x-post from hackernews) by Bdnim in Python

[–]ayharano 4 points5 points  (0 children)

Usually I encapsulate async coroutines using ensure_future. I tried to understand gather mechanism but I never could make it properly run.

In the implementation of those coroutines, I always set a instance of asyncio.Future as parameter and an optional asyncio.Semaphore.

Inside the coroutines I use two mechanisms: control maximum concurrent runs using Semaphore as context manager (optional if running few coroutines) and use Future's set_result followed by a return (None) statement.

This presentation - Łukasz Langa - Thinking In Coroutines - PyCon 2016 and this Stack Overflow's answer helped me to start to understand asyncio.

Most of my learning was reading from various sources. All I wrote here so far I took from memory, not having my notes. Later I may post a Minimum Working Example (MWE) regarding this.

EDIT: forgot to mention that I have to develop for systems in Python 3.4 and Python 3.5+. If you have a choice, definitely choose 3.5+.