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
Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Eela6 posted:

if you want to know more, there are sections in 'Effective Python', and a speech by Brett Slatkkn, the author of that book, about this.

you're talking about this talk i'm guessing? i liked it

huhu posted:

werkzeug.routing.BuildError: Could not build url for endpoint 'auth.login'. Did you mean 'login' instead?

i haven't used flask in a while but i've had that exact error when using url_for - have you imported login into the auth module there? if you have the same structure as that post you linked but you're not importing login into the __init__, you probably want auth.view.login instead

Adbot
ADBOT LOVES YOU

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

condolences

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Tigren posted:

3. So I don't capture lines that don't have one of those three allowed strings.

echoing the dict suggestion above

Python code:
def get_packages(pkg):
    sections = ('Available Packages', 'Installed Packages')
    section = None
    packages = {}

    outtxt = run_command('yum list %s' % pkg) 

    for line in outtxt:
        line = line.strip()
        if line in sections: 
            section = line
            continue
        if pkg in line and section: 
            packages.setdefault(section, []).append(line)
    return packages

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Boris Galerkin posted:

I kinda like the second choice because it seems much easier and way more intuitive to be able to just do

code:
self.foo = types.MethodType(module.foo, self)
But a lot of what I'm finding on the web suggest to use metaclasses without really saying why. Is there any practical differences to either way?

the first slide here is the quote i think of whenever metaclasses come to mind: http://www.vrplumber.com/programming/metaclasses.pdf

as far as methodtypes goes, keep in mind functions have __name__ attributes too, so you can do stuff like:

code:
import types


class Example(object):
    def __init__(self, value):
        self.value = value

    def bind_function(self, myfunc):
        return setattr(self, myfunc.__name__, types.MethodType(myfunc, self))


def print_value(self):
    print(self.value)


example = Example('greetings')
example.bind_function(print_value)
example.print_value()

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

SurgicalOntologist posted:

Huh. This is the first time in a while I've been surprised by Python.

keep in mind what you're actually doing - assigning an object that exists outside the class to a value within the class:

Python code:
def outer_func():
    pass


class RefClass(object):
    def __init__(self, func):
        self.func = func


print(outer_func) 
print(RefClass(func=outer_func).func)
is just going to print out the same object, which makes sense really

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

breaks posted:

That is within the instance not the class. Functions in the class's namespace will work as methods (with maybe some exceptions if you really try to break it).

I know that's maybe kind of pedantic but that's the distinction that changes the behavior so...

yeah i meant instance since i wrote the post right before it as a way to bind to instances, d'oh. just adding the function to a class' namespace still won't bind it, though

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
actually wait a minute, i'm an idiot apparently!

edit: been entirely too long since i looked at descriptor protocol stuff and somehow thought the same magic was needed for classes, i have no idea why

later edit: well, that was actually worth googling again, since you can just use the function's descriptors directly:

Python code:
class Test:
    pass


def foo(self):
    print("foo")


def bar(self):
    self.foo()
    print("bar")


Test.foo = foo
t = Test()
t.bar = bar.__get__(t)
t.bar()
i'm starting to remember why i never do this kind of thing though

Dex fucked around with this message at 22:29 on Apr 18, 2017

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Boris Galerkin posted:

What I want to do is have foo he defined per object

the descriptor bit in my last edit is probably what you want if you need access to the instance(self), unless i've confused myself completely again?

Python code:
class Welp(object):
    def __init__(self, func):
        self.foo = func.__get__(self)
        
def foo(self):
    print("foo")
    
def bar(self):
    print("bar")
    
def foo_bar(self):
    print("foo bar")
    
problems = (Welp(foo), Welp(bar), Welp(foo_bar))
[a.foo() for a in problems]
problems[0].foo()
problems[1].foo()
problems[2].foo()

output posted:

foo
bar
foo bar
foo
bar
foo bar

Dex fucked around with this message at 00:31 on Apr 19, 2017

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

shrike82 posted:

Which is a roundabout way of saying that Boris was right with his initial solution.

well i said he was directly right with my first reply, that last one is just using __get__ instead of methodtype syntax since it's new to me and reads a bit cleaner imo, since it just does that under the hood

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
i was going to suggest looking at GLEW but it seems kivy already has it as a dependency:

https://kivy.org/docs/installation/installation-windows.html posted:

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew

have you installed all those packages already?

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Gene Hackman Fan posted:

edit: I know I've heard other people having issues with this and added a line or two to the actual program to force... something, but it hasn't worked for me:
code:
from kivy import Config
Config.set('graphics', 'multisamples', '0')

seems to be a pretty common problem with windows 10 users:
https://github.com/kivy/kivy/issues/3576 - this one is fixed by the multisampling config you posted, so it's not that
https://github.com/kivy/kivy/issues/5071 - this one is pyinstaller specific
https://buffered.com/support/solve-opengl-error/ - this is just some random app that uses kivy

if you have the latest graphics drivers installed already, i'd say open an issue on kivy's github and see if they have anything helpful to add

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
looks like the site you're trying to read might have been updated, then. "'NoneType' object is not iterable" there is telling you that "per36_line_2016" is None, which means the line:

per36_line_2016 = soup.find("tr", id="per_minute.2016")

isn't finding anything whereas you're expecting a list(or some kind of iterable, at least) of things.

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

ButtWolf posted:

Yeah this completely killed my project. Looking at other sites to grab from, but making the url list looks awful on ESPN. Thank for your help everyone.
I would imagine this was done so it can't be scraped anymore.

edit: are you saying I can grab the file and save to hard drive, so I can do what I need to offline?

how often and where does this thing run? if js is populating the table you want, you could use selenium to open an actual browser window, and pass the .page_source to beautifulsoup:

Python code:
from selenium.webdriver import Chrome
browser = Chrome()
browser.get('http://www.basketball-reference.com/players/a/arizatr01.html?lid=carousel_player')
html = browser.page_source
browser.quit()
soup = BeautifulSoup(html, "html.parser")
per36_line_2016 = soup.find("tr", id="per_minute.2016") # This has 29 things in it. I don't know what the things are but I think they're what you want.
slow as balls in comparison to a direct request, but maybe that's ok for your use case.

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

ButtWolf posted:

I think I'm just gonna do it by hand... New method is above my skill level. Thanks.

the thing i posted actually pops chrome up in front of you, opens that page, copies the page source to the html var, then closes the window - there's nothing too complicated at work there, even if it looks brand new and insane. just read the selenium install docs, you need to drop the geckodriver executable somewhere on your path so your script knows how to actually talk to chrome

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Hughmoris posted:

For those that work with Excel, what Python library do you use?

i don't do anything complicated with excel but openpyxl suits me fine

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

sugar free jazz posted:

New to programming and python, and I made my first thing! Used Selenium to automate going into LexisNexis, then download all of the newspaper articles published that day from a few major newspapers that mention a couple different countries! It's janky, it's messy, but it actually does the thing I want it to which freaking owns. My low point was where I couldn't figure out how to deal with a few different frames on a page, and for a bit my workaround was send_keys((Keys.TAB * 57) + Keys.ENTER) to navigate to a button and click it yeeeesh. I feel like a lil kid and I wanna print it out and stick it on my refrigerator

congrats. selenium can be finicky depending on the sites you're dealing with, so having hacks like tabbing to the thing and sending ENTER isn't that weird tbh. in some cases it's significantly faster than searching multiple xpaths or whatever, just make sure you're raising some kind of sensible error if the thing breaks at that point!

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
it's expecting you to use the compose file - the redis container's address would then be resolved as 'redis', since that's its name, in this bit:

quote:

redis.exceptions.ConnectionError: Error -5 connecting to redis:6379. No address associated with hostname.

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

hooah posted:

The Dockerfile includes a command to install redis 2.10.5. I also installed the latest version on my local, and got the same result.

actually that command(https://github.com/jleetutorial/dockerapp/blob/master/Dockerfile#L2) is installing the python redis client, not a redis server

quote:

Sorry, the "compose file"? What's that?

this thing: https://github.com/jleetutorial/dockerapp/blob/master/docker-compose.yml

docker-compose lets you orchestrate multiple containers spinning up, and it handles linking them automatically. when you link containers in docker, you can resolve them by container name. see here: https://docs.docker.com/compose/install/#install-using-pip

basically, instead of running that app locally or building that dockerfile directly, you should be running "docker-compose up" in that repo. this would then start up the flask app and a redis server for it to talk to

so, the actual error message you're encountering is that the flask app is searching for redis:6379. 'redis' there is a hostname, specifically in this case the hostname of a separate container running a redis server. the application and dockerfile are both written with the expectation that the hostname 'redis' will resolve to a an address where a redis server is running(https://github.com/jleetutorial/dockerapp/blob/master/app/app.py#L6) - this is why trying to run it locally will get you nowhere unless you add 'redis' to your hosts file, or change the code to point to localhost or something

docker-compose is written in python so i suppose it's technically relevant to this thread, but probably not. is there a docker thread anywhere?

edit: note i haven't actually pulled down that repo to try it since i'm on my windows laptop so this is all guesswork. i have worked with docker a fair bit though

Dex fucked around with this message at 20:41 on Jun 3, 2017

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

Dominoes posted:

Loch - I've no idea why the Anaconda-specific commands aren't working.

Have you tried getting Python 3.6 running in Linux without Anaconda? That was really frustrating for me, and I never got it working!

were you trying to replace the system python version, because you really don't ever want to do that. building from source with configure, make and make altinstall then using python3.6/pip3.6 works fine for me on centos7. literally did this today as part of an automated setup for a vm i need to do stuff on

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
i'm a windows 7 holdout on my work laptop for reasons, does the windows subsystem for linux fix all those annoying things like not being able to run gunicorn because windows doesn't have fcntl and so on?

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

LochNessMonster posted:

Not sure if I should call them variables, they're more like connections/handlers right?

that syntax is just working with tuples. if you return multiple things like that, you can either catch them all in a tuple or assign them directly to variables

code:
>>> def blah():
...     return 1, 2
...
>>> a = blah()
>>> b, c = blah()
>>> print(a, b, c)
((1, 2), 1, 2)
>>> print(type(a), type(b), type(c))
(<type 'tuple'>, <type 'int'>, <type 'int'>)

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

funny Star Wars parody posted:

Lol if u have to think about the 64th decimal place in your code just lol

lmao if you don't understand every abstraction layer right down to how the rock we shoot lightning into to do numbers does stuff

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!
nobody mentioned web apps

Adbot
ADBOT LOVES YOU

Dex
May 26, 2006

Quintuple x!!!

Would not escrow again.

VERY MISLEADING!

KernelSlanders posted:

the guy who thinks theres something wrong with needing to know arcane implementation details.

Some of us work on projects where we do care about the 64th decimal place and we do care about messy internals.

i was making a joke about the guy psyducking at a beginner who asked a question about how numbers work. i am positively thrilled about your non-web-dev coding challenges and wish you well

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