Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
QuarkJets
Sep 8, 2008

NtotheTC posted:

I mean thats two separate points really. You want to avoid using system python for installing an apps dependencies into because you may have multiple apps on the same system that have conflicting requirements. If you already isolate the python environment becsuse you use containers or whatever then absolutely you can install things into system python.

The PEP makes it a bit simpler to isolate by default which would be nice in production without needing extra tooling. Even in containers its a nice bit of redundancy, but I can't work out if their goal with that PEP is to replace virtualenvs entirely or just be "virtualenv lite" to aid with teaching beginners

If you're on Windows (47% of respondents) then you don't even have a system python so it's moot. On linux a lot of those folks are probably using yum or apt-get to install whatever modules are provided for their flavor of linux, and that's almost definitely not going to hurt anything but will be able to take care of any dependencies for the most popular applications

A lot of operating systems even offer packages that are basically venvs. I know for a fact that RHEL does this, RHEL7's system python is still python2.7 but you can download and install all sorts of python flavors via yum and then at that point you're definitely not going to be harming the system because all of that poo poo is definitely not being used by the operating system.

QuarkJets fucked around with this message at 07:38 on Feb 8, 2019

Adbot
ADBOT LOVES YOU

Hadlock
Nov 9, 2004

NtotheTC posted:

Related: https://www.jetbrains.com/research/python-developers-survey-2018/

21% of Python devs dont use any sort of isolation for developing :psyduck:

Kind of interesting that 30-ish percent of users are using containers for a pure python environment. I always thought it was a novel way to do isolation (it's my preferred method) but I never thought it would catch on beyond 15% or so

SirPablo
May 1, 2004

Pillbug

Foxfire_ posted:

Write it back out to disk as a big binary array, memmap it, and let the OS swap it in and out as needed?

Not sure I follow this. I tried a memmap but seemed to just hose my machine.

KICK BAMA KICK
Mar 2, 2009

When doing type annotation is it conventional to import a module not otherwise needed solely to reference a type it defines in a parameter annotation, or to use a string literal instead? (Not asking about the issue of circular references.) The one prompting this question would be a datetime.date, standard library and presumably inexpensive, if that's a consideration, but I'm sure I'll come across others that aren't.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

KICK BAMA KICK posted:

When doing type annotation is it conventional to import a module not otherwise needed solely to reference a type it defines in a parameter annotation, or to use a string literal instead? (Not asking about the issue of circular references.) The one prompting this question would be a datetime.date, standard library and presumably inexpensive, if that's a consideration, but I'm sure I'll come across others that aren't.

Yes.

However, this is a potential gotcha if the module is something that takes a while to import.

PEP-563 should address that issue.

KICK BAMA KICK
Mar 2, 2009

Thermopyle posted:

Yes.

However, this is a potential gotcha if the module is something that takes a while to import.

PEP-563 should address that issue.
Thanks! Some of the spots where I'm having to import something I wasn't before are no big deal but some others seems like a clue that the code wasn't separating its concerns well enough.

Foxfire_
Nov 8, 2010

SirPablo posted:

Not sure I follow this. I tried a memmap but seemed to just hose my machine.

If you try to read 50GB into memory, you'll get an out-of-memory error since you don't have that much RAM (or if you have 50GB+ of swap enabled, you'll effectively get a crappy memmaped behavior).

Memory mapping it is telling the OS "When I try to access something in this region of memory, go read the surrounding little area from disk and pretend that was in the memory+cache it so that if I access it again you don't have to go all the way to disk". If you touch a new area and there's no free RAM to use to cache it, some other disk-backed page will get kicked out of RAM according to the OS's policies and the next program that touches that will have to wait while it reads in from disk (and boots something else).

If you're accessing the 50GB in a random unpredictable way (so that every read/write is likely to have to be loaded from disk and boot some other page to make space), there's not really anything you can do to make it run well besides get more RAM. But if the access pattern is sequential or has locality like most do, accesses will tend to be to regions that are already cached.

vikingstrike
Sep 23, 2007

whats happening, captain
You can use the dask read_csv function to load in multiple files the way you want. Read the docs.

You may want to pass over the data once though and put it in a format like parquet so it is faster to load and work with. You could consolidate the number of files so that the average size is about 100MB which is what I believe they recommend is a good size of a chunk.

vikingstrike fucked around with this message at 16:33 on Feb 9, 2019

Crack
Apr 10, 2009
When I try to use a virtual environment a big warning comes up from little snitch (a firewall) saying it is super insecure as "The code signature of “python3.7” is invalid. It may have been maliciously modified.". Is the new environment python meant to have a different code signature, and is it ok to allow this?

e: doesn't have an issue using venv, but virtualenv and pipenv apparently have modified code signatures.

Crack fucked around with this message at 14:12 on Feb 11, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Crack posted:

When I try to use a virtual environment a big warning comes up from little snitch (a firewall) saying it is super insecure as "The code signature of “python3.7” is invalid. It may have been maliciously modified.". Is the new environment python meant to have a different code signature, and is it ok to allow this?

e: doesn't have an issue using venv, but virtualenv and pipenv apparently have modified code signatures.

No one can answer this without more information such as what this firewall actually is, and exactly what you're doing. Did you download virtualenv from a torrent or something? What's the software that's yelling at you?

FWIW, heuristic-based security software like this always throws a lot of false positives; particularly when doing things like virtualenv does...moving and modifying binaries.

Crack
Apr 10, 2009
I found this in the end (although I'm just using system python and packages from pip, not brew). It's a known bug and the conclusion is that the OS itself determines that the code signature is invalid, and noone knows why.

VVVVV Ha, I actually tried to clarify with the parentheses but I can see how it might have actually had the reverse effect.

Crack fucked around with this message at 23:07 on Feb 11, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Well see, I didn't even know what I was talking about. When you said "little snitch" I thought you were just calling some software a name...I didn't realize that was actually a thing.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Just found out earlier you can run python -m http.server from a directory and it'll host it as a basic webserver :yosnice:

Dominoes
Sep 20, 2007

baka kaba posted:

Just found out earlier you can run python -m http.server from a directory and it'll host it as a basic webserver :yosnice:
It's convenient. I use a shimmed (For SPA routing and WASM MIME type) version of this in the examples and docs for my frontend framework.

Scrapez
Feb 27, 2004

Is there a better way to do this?

I have a string variable srv_name of the format: _sip._udp.servertype.domain.com.
I want to trim it to produce: domain.com.
Only the _sip._udp. portion is static and the rest of the values will be dynamic.

I'm using srv_domain_suffix = srv_name.split('.')[-3] + '.' + srv_name.split('.')[-2] + '.'

It seems to work fine but is there a better, more efficient way, of doing it?

QuarkJets
Sep 8, 2008

Scrapez posted:

Is there a better way to do this?

I have a string variable srv_name of the format: _sip._udp.servertype.domain.com.
I want to trim it to produce: domain.com.
Only the _sip._udp. portion is static and the rest of the values will be dynamic.

I'm using srv_domain_suffix = srv_name.split('.')[-3] + '.' + srv_name.split('.')[-2] + '.'

It seems to work fine but is there a better, more efficient way, of doing it?

You can use .join on a slice of the the last N entries from split:

code:
srv_domain_suffix = '.'.join(srv_name.split('.')[-2:])

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

rsplit with a limit might be slightly more efficient, if you know you just want the last 2 elements

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

baka kaba posted:

Just found out earlier you can run python -m http.server from a directory and it'll host it as a basic webserver :yosnice:

Just found out later this can give me corrupt zip files where Mongoose works just fine - :yosnice: revoked

NtotheTC
Dec 31, 2007


I think its very much not recommended for production. I like using it for testing port access on servers

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I just wanted an easy way to host files I can access through http on an android emulator, so I'm not bothered about the security - getting CRC errors is a no-no though :/

Hollow Talk
Feb 2, 2014
I just caught up on this thread after I had something like 200 unread posts lingering, and just wanted to thank Thermopyle for the :krad: example using Protocol. That might solve one of my remaining type-hint problems.

Somewhat related, I tend to use Union[<possible_types>, None], rather than Optional[<possible_types>] for readibility since I find it makes the intention a bit clearer and fits better into the paradigm to specify all possibly outcomes explicitly.

Unrelated: I went to FOSDEM two weeks ago, and there was a cool talk by a Redhat engineer about using oslo.config for config management.

Config management is something I have been struggling with for a while, especially tying together environment variables, config files and command-line arguments, as well as development environments. I played around with that last weekend a bit, and while some things are a bit odd (I opted not to use their global "Conf" object, since that seems to be something that exists because OpenStack uses it), I like that it lets you define options in one place (including defaults) and expose as config/env/command-line arguments with very little overhead, including generating the required argparse stuff automatically. It's not the slimmest library considering the principal components for config/env/command-line could also simply come from the stdlib, but I think it might just be worth it.

Here is a simple example that exposes options both as config file options as well as command-line options:

code:
import copy
from typing import Sequence, Tuple

from oslo_config import cfg

# Option groups
_socket_group = cfg.OptGroup(name='socket', help='Configure client/server socket options.')
_tcp_group = cfg.OptGroup(name='tcp', help='Configure TCP socket options.')
_unix_group = cfg.OptGroup(name='unix', help='Configure UNIX socket options.')

# Options
_socket_opts = [
    cfg.StrOpt(name='type', default='tcp', help='Client/server socket type.', choices=['tcp', 'unix'], short='t')
]

_tcp_opts = [
    cfg.HostAddressOpt(name='host', default='127.0.0.1', help='Host to bind socket on.', short='H'),
    cfg.PortOpt(name='port', min=1, max=65535, default=4242, help='Port to bind socket on.', short='P'),
]

_unix_opts = [
    cfg.StrOpt(name='socket', default='data-data_lineage.sock', help='UNIX socket path', short='S')
]

_opts = [
    (_socket_group, _socket_opts),
    (_tcp_group, _tcp_opts),
    (_unix_group, _unix_opts)
]


def list_opts() -> Sequence[Tuple[cfg.OptGroup, Sequence[cfg.Opt]]]:
    return [(g, copy.deepcopy(o)) for g, o in _opts]


class BaseConfig(cfg.ConfigOpts):
    def __init__(self) -> None:
        super(BaseConfig, self).__init__()

        for group, opts in _opts:
            self.register_group(group)
            self.register_opts(opts, group)
            self.register_cli_opts(opts, group)

        # Populate config object via its __call__ method. Otherwise, command-line argument parsing etc. won't work
        self.__call__()
That call to... __call__ is not very nice, but that's what you get if you don't use their global config object. :saddowns:

Hollow Talk fucked around with this message at 23:40 on Feb 17, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Hollow Talk posted:

I just caught up on this thread after I had something like 200 unread posts lingering, and just wanted to thank Thermopyle for the :krad: example using Protocol. That might solve one of my remaining type-hint problems.

Thanks. I really like Protocol and think structural typing is a much better fit for Python than "regular" types. Python is all about duck typing, and Protocols seem to mesh with that paradigm better.

Hollow Talk posted:

Somewhat related, I tend to use Union[<possible_types>, None], rather than Optional[<possible_types>] for readibility since I find it makes the intention a bit clearer and fits better into the paradigm to specify all possibly outcomes explicitly.

I lean toward using Optional on function arguments and Union on function return values. "Optional" seems to describe the intention of arguments with default values. However, I also get your argument against this.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Oh, some other typing-related thoughts/news:

1. There is finally a Literal type in typing_extensions, which should make numpy/scipy users happy. This lets you specify a literal value as the type to check. It's pretty common in python to use various string values instead of an enum. So, in a totally contrived example:

Python code:
def stupid_function(seterr: Literal['ignore', 'warn', 'raise', 'call', 'print', 'log']):
    """
    seterr: Can only be one of 'ignore', 'warn', 'raise', 'call', 'print', 'log'
    """
    pass
2. There is also a Final type in typing_extensions. You can now declare constants. You can also use it for methods (which means they can't be overriden in a subclass) and classes (which means the class can't be subclassed).

3. @overload is pretty neat

Python code:
from typing import Union, overload

from typing_extensions import Literal

@overload
def my_file_opener(name: str, mode: Literal['rb']) -> IO[bytes]:
    ...

@overload
def my_file_opener(name: str, mode: Literal['r']) -> IO[str]:
    ...

def my_file_opener(name: str, mode: str) -> IO[Any]:
    return open(filename, mode)

reveal_type(my_file_opener('python.txt', 'r'))  # typing.IO[builtins.str]
reveal_type(my_file_opener('python.jpg, 'rb')) # typing.IO[builtins.bytes]
(reveal_type is only understood by mypy...python won't know wtf that is)

4. I can't remember if I said this before, but typing_extensions is how mypy devs get around the fact that python's typing module can only be updated on new releases of python. Generally how it works is new types get discussed on the mailing list and github issues. They get experiemented on in mypy_extensions, get moved to typing_extensions when everyone is happy with them, then a PEP gets published and they get moved into python's typing module when PEP is accepted.

Thermopyle fucked around with this message at 17:36 on Feb 18, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Thermopyle posted:

Oh, some other typing-related thoughts/news:

1. There is finally a Literal type in typing_extensions, which should make numpy/scipy users happy. This lets you specify a literal value as the type to check. It's pretty common in python to use various string values instead of an enum. So, in a totally contrived example:

Python code:
def stupid_function(seterr: Literal['ignore', 'warn', 'raise', 'call', 'print', 'log']):
    """
    seterr: Can only be one of 'ignore', 'warn', 'raise', 'call', 'print', 'log'
    """
    pass
2. There is also a Final type in typing_extensions. You can now declare constants. You can also use it for methods (which means they can't be overriden in a subclass) and classes (which means the class can't be subclassed).

3. @overload is pretty neat

Python code:
from typing import Union, overload

from typing_extensions import Literal

@overload
def my_file_opener(name: str, mode: Literal['rb']) -> IO[bytes]:
    ...

@overload
def my_file_opener(name: str, mode: Literal['r']) -> IO[str]:
    ...

def my_file_opener(name: str, mode: str) -> IO[Any]:
    return open(filename, mode)

reveal_type(my_file_opener('python.txt', 'r'))  # typing.IO[builtins.str]
reveal_type(my_file_opener('python.jpg, 'rb')) # typing.IO[builtins.bytes]
(reveal_type is only understood by mypy...python won't know wtf that is)

4. I can't remember if I said this before, but typing_extensions is how mypy devs get around the fact that python's typing module can only be updated on new releases of python. Generally how it works is new types get discussed on the mailing list and github issues. They get experiemented on in mypy_extensions, get moved to typing_extensions when everyone is happy with them, then a PEP gets published and they get moved into python's typing module when PEP is accepted.

That’s pretty neat and I didn’t know about that. Is there a place I can read, watch, or listen about these types of “hidden/advanced” features? Searching for anything Python related seems to be a shitshow cause it’s just endless pages of blog posts that fall into one of two categories: extremely basic stuff on the level of “this is a list” or the “here is a curated list of awesome libraries” where it’s the same things listed as every other list without actually going into detail about why it’s awesome.

Dominoes
Sep 20, 2007

Boris Galerkin posted:

That’s pretty neat and I didn’t know about that. Is there a place I can read, watch, or listen about these types of “hidden/advanced” features? Searching for anything Python related seems to be a shitshow cause it’s just endless pages of blog posts that fall into one of two categories: extremely basic stuff on the level of “this is a list” or the “here is a curated list of awesome libraries” where it’s the same things listed as every other list without actually going into detail about why it’s awesome.
You're forgetting the Django vs Flask genre.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Boris Galerkin posted:

That’s pretty neat and I didn’t know about that. Is there a place I can read, watch, or listen about these types of “hidden/advanced” features?

Over the years, I've found a good way is to follow the issue trackers of various projects. Github makes this pretty easy (except their notification system is terrible).

That last post of mine was as a result of me clicking through an email notification to the python/typing issue tracker and getting caught up wikipedia-style reading other related issues where core devs talk about how to solve different problems, what they're working on, pull requests they're discussing, etc.

EVIL Gibson
Mar 23, 2001

Internet of Things is just someone else's computer that people can't help attaching cameras and door locks to!
:vapes:
Switchblade Switcharoo

Hadlock posted:

Kind of interesting that 30-ish percent of users are using containers for a pure python environment. I always thought it was a novel way to do isolation (it's my preferred method) but I never thought it would catch on beyond 15% or so

In the field i am with people making "easy" testing tools in python they will always surprise you with what requirements they want.

containers is the only way to making any of these god drat enviroments portable.

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Thermopyle posted:

Over the years, I've found a good way is to follow the issue trackers of various projects. Github makes this pretty easy (except their notification system is terrible).

That last post of mine was as a result of me clicking through an email notification to the python/typing issue tracker and getting caught up wikipedia-style reading other related issues where core devs talk about how to solve different problems, what they're working on, pull requests they're discussing, etc.

Where can I read what you wrote in the second paragraph?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Umm, look at the python/typing repo on github.

mbt
Aug 13, 2012

shoutout to MSS for being the best image capture library for real time analysis
https://python-mss.readthedocs.io/examples.html

pros:
-it's fast as hell
-it's really really fast

there are still many blogs and tutorials that recommend PIL's imagegrab or even weirder pyautogui's screenshot which is just imagegrab imported on demand. that might be ok if you're not time constrained, but if you're like me trying to write cheat software you should probably use mss which can capture your entire monitor at 20 fps pretty easily.

most of you might already know this but after using it the past few weeks it's good, folks.

Hadlock
Nov 9, 2004

Has anyone figured out how to re-enable pylint message codes in vscode? This was added as a "feature" in 2019.1.0 ... GitHub issue #2906

Personally I like the message codes as it's easy to #pylint: disable=W0105 or whatever when necessary, so my linter problems stay clean and I can focus on actual problems

Also googling a message code is way way more efficient

Hadlock fucked around with this message at 07:49 on Feb 22, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Thermopyle posted:

Umm, look at the python/typing repo on github.

Oh, I thought you meant like another message board or something. Thanks.

I'm digging into tox right now and it's a bit confusing. Is tox suppose to only run tests or do people use it for more than that? Here's what my simple tox.ini file looks like right now:

code:
[tox]
envlist = lint,py37,mypy

[testenv]
deps = pytest
commands = pytest
usedevelop = true

[testenv:lint]
deps = black
commands = black myproject tests

[testenv:mypy]
deps = mypy
commands = mypy myproject
What I was going for was that I wanted tox to run black before every test, and then afterwards run mypy, which I think is what I've done by setting the envlist this way. It works, but I'm not sure if I'm doing it right.

e: In a way this feels like a makefile but specifically for python.

Boris Galerkin fucked around with this message at 10:10 on Feb 22, 2019

Vegetable
Oct 22, 2010

I'm trying to compile a pattern to match a basic linear equation of the format 3y<=1+2x

However, my regex expression is giving me an empty group at the end:

(?<sign>\+|\-?)
(?<coeff>[1-9]*)
(?<var>[a-z]?)
(?<equality>>=|<=|=?)

I understand it's because all of my capture groups are optional. In actuality, there will always be at least one variable or one coefficient, so my capture groups aren't reflecting that reality correctly.

My efforts to use the OR operator have failed. I can't figure out how to make it work. Might somebody be able to point me in the right direction?

Hollow Talk
Feb 2, 2014

Vegetable posted:

I'm trying to compile a pattern to match a basic linear equation of the format 3y<=1+2x

However, my regex expression is giving me an empty group at the end:

(?<sign>\+|\-?)
(?<coeff>[1-9]*)
(?<var>[a-z]?)
(?<equality>>=|<=|=?)

I understand it's because all of my capture groups are optional. In actuality, there will always be at least one variable or one coefficient, so my capture groups aren't reflecting that reality correctly.

My efforts to use the OR operator have failed. I can't figure out how to make it work. Might somebody be able to point me in the right direction?

Which parts do you need separetely? Realistically, I think I would probably go at this a bit differently. I would probably split this into three via ([^><=]+)([=<>]+)([^><=]+). This splits the left-hand, equality, and right-hand side pretty much regardless of actual content. Afterwards, you can then go and parse out individual bits out of these, while you can be reasonably sure that at least something has to be in each one of those groups. You can then go and and do something like [+-]{0,1} to capture +/- signs etc.

I think some of your problems might disappear if you specify occurences explicitly, i.e. via the {min,max}-syntax, rather than the zero-or-more/one-or-more syntax.

edit: More generally, depending how complex the equations you deal with get, you will probably have to either loop through the split parts, or use recursive regex, since there isn't necessarily a limit to how many operators/operands your equation might have.

Hollow Talk fucked around with this message at 13:27 on Feb 23, 2019

Vegetable
Oct 22, 2010

I'm doing this as homework for a course. With the example of input string '3x <= 6 + 2y + 7z', I'm supposed to get this:

[('', '3', 'x', '<='), ('', 6, '', ''), ('+', '2', 'y', ''), ('+', '7', 'z', '')]

The only thing I'm able to provide is the pattern -- I can't clean the input string, can't split it. The system takes the pattern and runs a findall with the string.

e: You were right, I just needed to specify the coefficient group ([1-9]*) as mandatory rather than optional. Glaring oversight. Thanks!

Vegetable fucked around with this message at 16:22 on Feb 23, 2019

QuarkJets
Sep 8, 2008

... that's a loving goofy homework problem

crazysim
May 23, 2004
I AM SOOOOO GAY
I like using debuggex and other online regexp tools to debug those.

punished milkman
Dec 5, 2018

would have won

Meyers-Briggs Testicle posted:

shoutout to MSS for being the best image capture library for real time analysis
https://python-mss.readthedocs.io/examples.html

pros:
-it's fast as hell
-it's really really fast

there are still many blogs and tutorials that recommend PIL's imagegrab or even weirder pyautogui's screenshot which is just imagegrab imported on demand. that might be ok if you're not time constrained, but if you're like me trying to write cheat software you should probably use mss which can capture your entire monitor at 20 fps pretty easily.

most of you might already know this but after using it the past few weeks it's good, folks.

is there a good resource/example tutorial i can read about this kind of thing? sounds extremely cool

mbt
Aug 13, 2012

punished milkman posted:

is there a good resource/example tutorial i can read about this kind of thing? sounds extremely cool

if your goal is something like this https://www.youtube.com/watch?v=iXUIOx8ZSPw
then https://automatetheboringstuff.com/chapter18/ is a good baseline, its also pretty easy.

Real Image Analysis is like https://www.pyimagesearch.com/2018/07/16/opencv-saliency-detection/ and can get as complex as you want to make it. check opencv docs, a lot of different methods are available.

the tools are all there, developing an efficient heuristic is the hard part. how does one take a static image and find an enemy's head to zoom to click on? good question, I'll let you know when I find one. it's certainly not the best way to do it (learn cpp and write a dll wrapper if your goal is sicknasty headshots in apex legends) but it sounded interesting to try.

Adbot
ADBOT LOVES YOU

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

Meyers-Briggs Testicle posted:

shoutout to MSS for being the best image capture library for real time analysis
https://python-mss.readthedocs.io/examples.html

pros:
-it's fast as hell
-it's really really fast

there are still many blogs and tutorials that recommend PIL's imagegrab or even weirder pyautogui's screenshot which is just imagegrab imported on demand. that might be ok if you're not time constrained, but if you're like me trying to write cheat software you should probably use mss which can capture your entire monitor at 20 fps pretty easily.

most of you might already know this but after using it the past few weeks it's good, folks.

I've played with MSS before, but have gone back to using PyAutoGUI with OpenCV as a backend. The jump from the Python backend to the OpenCV backend is crazy.

One of the things that I use the most is pyautogui.locateCenterOnScreen(). I flicked through the MSS API but don't see an equivalent. How would I use that if I switch to MSS?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply