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.
 
  • Locked thread
Stringent
Dec 22, 2004


image text goes here

Dominoes posted:

Thanks dudes! I'm asking because I set up a simple website to help out at work, that only consists of a set of links and a roster of names/contact info. To view the roster, you need to be logged in to a verified account, and a few people will be able to edit the roster and links. This seemed like Flask territory, but the db, admin and auth system are already taking away some of the simplicity.

Do yourself a favor and just go ahead and do it in Django. These projects always balloon and you're not gaining that much simplicity from using Flask.

The real use case for Flask is apps that live behind an http server, but are not websites. Anything that might use html, css or JavaScript should probably just be done in Django imo.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

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

I never understand these arguments to use Flask for small projects because Django comes with more than you need.

Just don't use the parts you don't need!

hooah
Feb 6, 2006
WTF?

flosofl posted:

If you're willing to spend money, I like Team Treehouse. ($25/mo. or $199/yr) You get access to all the training, so not just Python.

Even though I considered myself "intermediate" with the automation I'd do I thought I'd give it a spin for the Data Science course they had. Turns out my poo poo worked out sheer stubbornness. I was a monkey banging the ground with a wrench. I ended up doing their whole Learn Python and I definitely learned I had Been Doing It Wrong. In fact it made crystal clear subjects that had confused and frightened me before like Classes, Methods and Inheritance (I typically wrote brute-force, bulldozer code before).

I'm in a much better place programming wise and more confident with my knowledge. In fact with the solid foundation, I find it much easier get up to speed on newer topics.

I definitely wouldn't call them advanced courses or really applicable to someone with a really solid mastery in Python, but they're definitely good for the beginning to intermediate programmer.

Be aware it is Python 3 they use.

I'm a fan and I'm going to be starting the Swift track when I wrap up a project I'm eyeball deep in at work.

Any suggestions for poorer/cheaper folk? I've done a little codeingame, but it doesn't really require any particular quality of code. I've considered translating some of my C++ projects from school; would this be a decent way to get more familiar with Python's classes?

Cingulate
Oct 23, 2012

by Fluffdaddy
I want to make a dynamic visualisation for a set of data. On a website, visitors should be able to type in (or select from a pulldown menu) a title and get a scatterplot with the corresponding values.
I have the static image ready - it's just a pandas dataframe visualised with seaborn and a bit of custom matplotlib.

What's the recommended framework here?

Gothmog1065
May 14, 2009
Is there another site as good as stack overflow for programming questions? Our work content filter is set up to block access to it right now as "Social Media". Gonna talk to the boss about seeing if networking will allow an exemption to it but it's annoying as poo poo to try to learn crap on my downtime.

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Cingulate posted:

I want to make a dynamic visualisation for a set of data. On a website, visitors should be able to type in (or select from a pulldown menu) a title and get a scatterplot with the corresponding values.
I have the static image ready - it's just a pandas dataframe visualised with seaborn and a bit of custom matplotlib.

What's the recommended framework here?
I just did this kind of thing with Flask and JQuery. The site just acts as a little frontend to the processing application, basically. Django would be complete overkill unless you have some weird requirements.

Cingulate
Oct 23, 2012

by Fluffdaddy

Ghost of Reagan Past posted:

I just did this kind of thing with Flask and JQuery. The site just acts as a little frontend to the processing application, basically. Django would be complete overkill unless you have some weird requirements.
You vastly overestimate my programming skills and how much time I can afford on learning a web framework. I was thinking about something like booked or mpld3.

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Cingulate posted:

You vastly overestimate my programming skills and how much time I can afford on learning a web framework. I was thinking about something like booked or mpld3.
Here, let me write you the basic Flask stuff.

Python code:
from flask import Flask, render_template, request

visualizer = Flask(__name__)

@visualizer.route('/', methods=['GET'])
def home():
    return render_template('index_template.html')

@visualizer.route('/results.html', methods=['POST','GET'])
def results():
    # set up a template with some input in a form with a select element with the name 'plot-options'
    if request.method == 'POST':
        if request.form['plot-options'] == 'scatterplot':
            # do your stuff here to call your Python code
            # make sure you assign the file name to a variable called chartfile before you finish this stuff; it could just be 'image.png' or whatever.

            return render_template('plot_template.html', chartfile=chartfile)

if __name__ == '__main__':
    visualizer.debug = True
    visualizer.run()
You would need two template files. The index_template could be a straight HTML file without any funny business that has a form submit button that POSTs to /results.html . The results file could be a straighforward HTML file with the following in it where you want your image displayed

code:
<img src="{{ chartfile }}">
That's it. I mean, you can do a lot more but that's basically the minimum necessary.

I don't know anything about booked or mpld3, but if you say you're generating static images this should work fine (MPLD3 looks like it's for making things more interactive than it sounds like you're going for, but if interactivity is your goal, that might be the faster route).

Ghost of Reagan Past fucked around with this message at 16:49 on Sep 7, 2015

Cingulate
Oct 23, 2012

by Fluffdaddy
Sorry, what I wrote about the static image was confusing - I meant, I have done a static representation of what I want to do dynamically online.

What you wrote seems nice and all, but I'm really wondering about what interactive data visualization suite to choose :)

Emacs Headroom
Aug 2, 2003

Cingulate posted:

I want to make a dynamic visualisation for a set of data. On a website, visitors should be able to type in (or select from a pulldown menu) a title and get a scatterplot with the corresponding values.
I have the static image ready - it's just a pandas dataframe visualised with seaborn and a bit of custom matplotlib.

What's the recommended framework here?

Shiny is made for exactly this, though it's R not Python

Cingulate
Oct 23, 2012

by Fluffdaddy

Emacs Headroom posted:

Shiny is made for exactly this, though it's R not Python
I know, I was wondering about the Shiny of Python.

OnceIWasAnOstrich
Jul 22, 2006

You want the visualization itself to be dynamic? Bokeh will do that for you. There is also spyre which is more of a web framework specifically for data visualization if you are looking for a wrapper around web framework and templating libraries to make that part of your life easier.

Proteus Jones
Feb 28, 2013



hooah posted:

Any suggestions for poorer/cheaper folk? I've done a little codeingame, but it doesn't really require any particular quality of code. I've considered translating some of my C++ projects from school; would this be a decent way to get more familiar with Python's classes?

There's this:
http://www.diveintopython3.net

or this:
http://www.python-course.eu/python3_course.php

Gothmog1065 posted:

Is there another site as good as stack overflow for programming questions? Our work content filter is set up to block access to it right now as "Social Media". Gonna talk to the boss about seeing if networking will allow an exemption to it but it's annoying as poo poo to try to learn crap on my downtime.

I'm going to lean toward no. Whenever I google for a coding issue or clarification on an run error usually the 1st page of results is almost all Stack Overflow. The quality of the results taper off sharply after the Stack Overflow.

Get them to allow Stack Exchange sites in general ASAP.

Proteus Jones fucked around with this message at 21:16 on Sep 7, 2015

BigRedDot
Mar 6, 2008

Cingulate posted:

I know, I was wondering about the Shiny of Python.

Bokeh is part-way there, and we are working on much more.

Edit:

Possibly useful: http://bokeh.pydata.org/en/latest/docs/user_guide/interaction.html#defining-callbacks You can do alot with our recent "JS callbacks" and there is an in-flight PR to allow writing those in python to be transpiled to JS (currently only for python 3 due to the underlying library supporting only py3 currently)

Cingulate
Oct 23, 2012

by Fluffdaddy
Okay I think I want something very simple, I'm just bad at computers.

Based on the recommendations, I've set up a bokeh notebook. I want a dropdown list (actually, a select widget). On a selection, I want to pass the selected value to another function that updates the plot.

I can't figure out how to access the last value selected on the widget (select.value always returns the default), or how to trigger anything on the callback.

The documentation is frankly said overwhelming - I've never used Javascript in my life, I just want to make a scatterplot!

Edit:
code:
from bokeh.models.widgets import Select
from bokeh.io import output_file, show, vform, output_notebook

output_notebook()
select = Select(title="Option:", value="foo", options=["bar", "baz"])
select.on_change('value', print)
show(vform(select))
I would have expected it to print the selected value when I click an option.

Cingulate fucked around with this message at 22:54 on Sep 7, 2015

Proteus Jones
Feb 28, 2013



Let's talk VCS.

Here's my situation. It's just me and all my projects are local. They're mostly network automation to do same task or tasks thousands of times given a csv file or files of system information. I develop my utilities on a rMBP using PyCharm and I'm using anaconda (python 3.4.3).

As background I've just taken a look at one of the first network utilities I've made and I've decided to do a major update to it to make it more flexible and easier on the eyes. What I have been doing is create a new project directory, copying over the old files, and opening the new directory in PyCharm.

PyCharm itself tracks a very tiny amount of changes, which has served me OK so far, but if I wander down a wrong path for too long, I realized I have no real recourse other than doing a "poor mans" VCS. i.e. Each time I do a change (other than fixing syntax) I put a version number on the file. This is getting out of control for me.

So... what's the recommended method? GitHub is out for now, since I don't want to pay to have "private" projects and there's some stuff that could get me fired if I put it in a public one. But I do have git installed from when I was looking at GitHub. I can also probably get mercurial or others on my box via homebrew if necessary.

As an addendum to that question, are there any good tutorials on getting up to speed on VCS? I've never used any before as I'm not really a programmer, but I've started writing more and more Python as part of an automation push that's basically my 20% project at work.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat
You don't need GitHub, you can use Git locally. It sounds like it would pretty much cover your needs with a simple local repository. With a single user, it's surprisingly easy to get everything set up. If you want remote code hosting, try Bitbucket.org, which is free for up to five users for a private repo.

You can get started here:
https://git-scm.com/book/en/v1/Git-Basics-Getting-a-Git-Repository

Proteus Jones
Feb 28, 2013



Fergus Mac Roich posted:

You don't need GitHub, you can use Git locally. It sounds like it would pretty much cover your needs with a simple local repository. With a single user, it's surprisingly easy to get everything set up. If you want remote code hosting, try Bitbucket.org, which is free for up to five users for a private repo.

You can get started here:
https://git-scm.com/book/en/v1/Git-Basics-Getting-a-Git-Repository

Thanks!

QuarkJets
Sep 8, 2008

Yeah I've never actually used GitHub; git is a great tool, though!

narthollis
May 7, 2013

QuarkJets posted:

Yeah I've never actually used GitHub; git is a great tool, though!

Indeed, before Github came along I used to push to my local server using mapped network drives - I really like the way that git is reasonably uncaring about your transfer protocol.

Gothmog1065
May 14, 2009
Okay, I need some help, namely with the error that's being thrown. Basically link_list is a list of tuple pairs ( ex: list = [(1,2),(2,3)...] ), but I'm having issues removing them at the end. Here's my lovely code. I'm working through this myself, so I'm hoping to get that specific part working before I move on (then I'll get advice on how to be less stupid with my code).


**EDITED CODE**

Python code:
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

# n: the total number of nodes in the level, including the gateways
# l: the number of links
# e: the number of exit gateways
n, l, e = [int(i) for i in input().split()]
link_list = []
for i in range(l):
	# n1: N1 and N2 defines a link between these nodes
	n1, n2 = [int(j) for j in input().split()]
	link_list.append((n1,n2))
	
print(link_list, file=sys.stderr)
gateways = []
for i in range(e):
	ei = int(input())  # the index of a gateway node
	gateways.append(ei)
#print(gateways,file=sys.stderr)
# game loop

while 1:
	si = int(input())  # The index of the node on which the Skynet agent is positioned this turn
	enemy = si #Let's use less stupid variable names
	disconnect = ()
	
	for links in link_list:
		#print(links,file=sys.stderr)
		print(links[0],links[1],enemy,file=sys.stderr)
		if (links[0] == enemy) and (links[1] in gateways):
			disconnect = (enemy, links[1])
			print("One", disconnect, file=sys.stderr)
			break
		elif (links[1] == enemy) and (links[0] in gateways):
			disconnect = (enemy, links[0])
			print("Two", disconnect, file = sys.stderr)
			break
		else:
			disconnect = link_list[-1:]
			print("Three",disconnect, file=sys.stderr)
			#break
	
	print(disconnect[0], file=sys.stderr)
	link_list.remove(disconnect[0]) <--------- error line
	print(str(disconnect[0]) + " " + str(disconnect[1]))
The error being thrown is:

code:
IndexError: list index out of range
at Answer.py. in <module> on line 48
I went ahead and marked the line that is having the issue.

Gothmog1065 fucked around with this message at 02:22 on Sep 9, 2015

vikingstrike
Sep 23, 2007

whats happening, captain

Gothmog1065 posted:

Okay, I need some help, namely with the error that's being thrown. Basically link_list is a list of tuple pairs ( ex: list = [(1,2),(2,3)...] ), but I'm having issues removing them at the end. Here's my lovely code. I'm working through this myself, so I'm hoping to get that specific part working before I move on (then I'll get advice on how to be less stupid with my code).

Python code:
# n: the total number of nodes in the level, including the gateways
# l: the number of links
# e: the number of exit gateways
n, l, e = [int(i) for i in input().split()]
link_list = []
for i in range(l):
	# n1: N1 and N2 defines a link between these nodes
	n1, n2 = [int(j) for j in input().split()]
	link_list.append((n1,n2))
	
gateways = []
for i in range(e):
	ei = int(input())  # the index of a gateway node
	gateways.append(ei)

# game loop
while 1:
	si = int(input())  # The index of the node on which the Skynet agent is positioned this turn
	enemy = si #Let's use less stupid variable names
	for links in link_list:
		print(links[0],links[1],enemy,file=sys.stderr)
		if (links[0] == enemy) and (links[1] in gateways):
			disconnect = (enemy, links[1])
			#print("One", disconnect, file=sys.stderr)
			break
		elif (links[1] == enemy) and (links[0] in gateways):
			disconnect = (enemy, links[0])
			#print("Two", disconnect, file = sys.stderr)
			break
		else:
			disconnect = link_list[-1:]
			#print("Three",disconnect, file=sys.stderr)
			break
			
	link_list.remove(disconnect) #< -------- This is the line
	print(str(disconnect[0]) + " " + str(disconnect[1]))
The error being thrown is:

code:
ValueError: list.remove(x): x not in list
at Answer.py. in <module> on line 43
I went ahead and bolded the line that is having the issue.

Indentation error technically, but really a scope problem. You define "disconnect" at a level lower (inside the for loop) than what you are calling (inside the while loop).

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

flosofl posted:

PyCharm itself tracks a very tiny amount of changes, which has served me OK so far, but if I wander down a wrong path for too long, I realized I have no real recourse other than doing a "poor mans" VCS. i.e. Each time I do a change (other than fixing syntax) I put a version number on the file. This is getting out of control for me.

PyCharm has Git integration so you get a nice UI and tools right in the IDE

https://www.jetbrains.com/pycharm/help/using-git-integration.html

It doesn't handle everything (I've had to crack open the command line to stop it tracking a previously tracked file) but for your general day-to-day version control it's great

Gothmog1065
May 14, 2009

vikingstrike posted:

Indentation error technically, but really a scope problem. You define "disconnect" at a level lower (inside the for loop) than what you are calling (inside the while loop).

Do I have to do something more than defining it outside the for loop (Adding it the line above?). That doesn't seem to be fixing anything (even setting the variable outside the while loop), nor does putting the removal into the for loop (which doesn't really do what I want).

print(disconnect) directly above that line and it outputs [(x,y)], print(disconnect[0]) gives just (x,y) (Which seems to be what I want), but link_list.remove(disconnect[0]) throws an out of range area. Am I moving the wrong direction?

Proteus Jones
Feb 28, 2013



baka kaba posted:

PyCharm has Git integration so you get a nice UI and tools right in the IDE

https://www.jetbrains.com/pycharm/help/using-git-integration.html

It doesn't handle everything (I've had to crack open the command line to stop it tracking a previously tracked file) but for your general day-to-day version control it's great

I already got it up and running with PyCharm. It's pretty drat pain-free so far.

I use time machine so poo poo is backed up, but they all live on a directory mapped to a cloud drive, so I can offload having to worry about both my machine and my local backup being destroyed by catastrophe. Of course, if some happens at that level, I'm sure my utility scripts will be the last thing on my mind.

Proteus Jones fucked around with this message at 22:37 on Sep 8, 2015

Proteus Jones
Feb 28, 2013



Gothmog1065 posted:

Do I have to do something more than defining it outside the for loop (Adding it the line above?). That doesn't seem to be fixing anything (even setting the variable outside the while loop), nor does putting the removal into the for loop (which doesn't really do what I want).

print(disconnect) directly above that line and it outputs [(x,y)], print(disconnect[0]) gives just (x,y) (Which seems to be what I want), but link_list.remove(disconnect[0]) throws an out of range area. Am I moving the wrong direction?

Put break points in and step through the code to where the value goes wonky. I'd probably set a break point every time disconnect should receive a value and validate it's an expected value. Also stop right before everything blows up and look at what things are vs. what you expect.

Also, I'd probably do a
code:
disconnect = []
before entering the loop.

Actually, I'd probably put all my list initializations at the start of the function.


But definitely run it through a debugger.

Sorry I misread, you're removing the value of disconnect from link_list.

What you're doing is trying to remove a list of tuples from link_list instead of the tuple itself. That will break because link_list[x] is not equal to disconnect. Disconnect is a list of one tuple, so you need to give disconnect the index of that tuple. In this case: [0]

try:
code:
link_list.remove(disconnect[0])
That remove a specific tuple from a list of tuples.

Proteus Jones fucked around with this message at 23:23 on Sep 8, 2015

Gothmog1065
May 14, 2009

flosofl posted:

try:
code:
link_list.remove(disconnect[0])
That remove a specific tuple from a list of tuples.


Gothmog1065 posted:

print(disconnect) directly above that line and it outputs [(x,y)], print(disconnect[0]) gives just (x,y) (Which seems to be what I want), but link_list.remove(disconnect[0]) throws an out of range area. Am I moving the wrong direction?

Yeah, I already tried that and am getting an "out of range error." I had to leave work so I didn't poke it anymore at that time. I'll see if I can poke it more tomorrow.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

vikingstrike posted:

Indentation error technically, but really a scope problem. You define "disconnect" at a level lower (inside the for loop) than what you are calling (inside the while loop).

I feel like I'm going crazy, I thought control blocks in Python don't make a new scope?

Gothmog, you need a debugger. I'm not a very knowledgeable programmer so I'm sorry if this is wrong, but I'm pretty sure the else code path can't fail unless link_list is empty(as long as you do disconnect[0] to get the tuple and not the list of one tuple), so if the other code paths are failing, you need to use the debugger to determine why link_list doesn't contain the values that you expect.

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

Gothmog1065 posted:

Yeah, I already tried that and am getting an "out of range error." I had to leave work so I didn't poke it anymore at that time. I'll see if I can poke it more tomorrow.

I'm not entirely sure what you're doing, but your first piece of code looks like it iterates over link_list, examines a bunch of 2-tuples, then sets disconnect to a 2-tuple. It resets this over and over until it finishes with the list, then once it leaves the loop, it calls link_list.remove() with whatever disconnect was last set to. Which should be whatever the result is for the last tuple in the list? You probably don't want to do that I'm guessing, and the remove call is meant to happen for each tuple in the list, after you've determined what to do with it

The other thing I noticed is your second case checks if the tuple is (gateway, enemy), but then it sets disconnect to (enemy, gateway), which is a different tuple and won't match the remove call, if that's what's meant to be happening. Your last case sets disconnect to the last element of the list, so you're removing elements from the end (is that what you want?), and if you do it in the loop you'll be modifying the list you're iterating over, which isn't usually a good idea (you'd generally iterate over a copy and modify the original)

Personally I'd stick a breakpoint on the problem line and run a debugger on it, see what the state of disconnect and link_list is when it falls over

Gothmog1065
May 14, 2009
I think the biggest problem with a debugger is the while loop and the fact that codingame is what breaks the loop, and I'd probably make it worse by trying to escape the while loop (Even though it's probably a timer or something else that breaks it). It's hard to shove that code into a debugger when there's so much external data going into it. Let me try to rework it some.

Here is a link to the actual game (You can "continue without an account" in the upper right). That way you can see what I'm doing. Just remember, I'm not even close to finished yet and I'm still thinking about some of the final cases. I'll go back and edit in the modified code.

What it's SUPPOSED to be doing is a multi step process. I'll make better comments in the code too.

There is an enemy on the board who has to follow the links to get to a gateway. The first two for loops are simply setting up the links and the gateways. My job is to 'break' the links so the enemy can't travel down them, and break all links so the enemy can't get to the gateway.

each tuple is x,y for the psuedocode:

code:
for each of the links in the link list:
    If the x link value and the enemy are the same and the y value is the gateway:
        break the link (enemy, gateway)
    if the y link value and the enmy are the same and the x value is the gateway:
        break the link(gateway,enemy)
    else: 
        break the last link (just some random poo poo in there until I get the rest done)

remove the broken link from the link_list, which causes the while loop to go through again, which shouldn't cause problems with the for over the link_list
print the answer (which is just breaking up the disconnect in a way the game can read)
Future things to add in:
- Attempt to see if there is a "closest path" to the gateway, which is going to be fun
- Check to see which way the enemy is going in case of multiple gateways.

possible problems:
If somehow I get the link numbers reversed as x is not always < y.

Now, theoretically condition A and B should always allow me to win, but I've got to get the enemy close enough to a gateway to do those conditions. I've probably got some other things to look at adding in, but I'm trying to do this a bit at a time, by breaking it down into smaller puzzles (Basically each test if you want to see visually what the links look like).

I guess that's my thought patterns on how I'm tackling the code as well.

e: I updated the code here in the previous post and the error, as not to keep spamming this page. If I keep editing, I'll get a github link.

e2: I'm downloading Pycharm to debug with, I'll post a github of that when I get it built.

Gothmog1065 fucked around with this message at 02:25 on Sep 9, 2015

BigRedDot
Mar 6, 2008

Cingulate posted:

Okay I think I want something very simple, I'm just bad at computers.

Based on the recommendations, I've set up a bokeh notebook. I want a dropdown list (actually, a select widget). On a selection, I want to pass the selected value to another function that updates the plot.

I can't figure out how to access the last value selected on the widget (select.value always returns the default), or how to trigger anything on the callback.

The documentation is frankly said overwhelming - I've never used Javascript in my life, I just want to make a scatterplot!

Edit:
code:
from bokeh.models.widgets import Select
from bokeh.io import output_file, show, vform, output_notebook

output_notebook()
select = Select(title="Option:", value="foo", options=["bar", "baz"])
select.on_change('value', print)
show(vform(select))
I would have expected it to print the selected value when I click an option.
Well, you don't just want a scatter plot. If that's all you want it's about three three lines of python code (including imports). You want a scatter plot with computations and updates all nicely linked to interactive UI. There's lots of potential use-cases, and JS callbacks is one just option, but there is a PR in-flight to allow writing the callbacks in python to be compiled to JS automatically, which will be great. That said, if you want widgets in a just in an IPython notebook, I'd recommend using IPython interactors for now. Those are dead simple and work great, here's an example: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb Bokeh widgets like the ones you are trying to use require a Bokeh server, and I would say hold off on that a month or two since we are in the process of re-writing the thing entirely to make it much better and simpler to use.

Speaking of the server re-write, an interview I did for podcast.__init__ last month just went up, and I speak about the plans quite a bit towards the end: http://ow.ly/RVWLq

EDIT: Also FYI you'll have to run the linked notebook locally. GitHub scrubs all Javascript from it's notebook previews, so things like Bokeh plots and IPython interactors don't show up, and in any case you actually want python to execute in response to the dropdown so that requires a real IPython kernel running.

BigRedDot fucked around with this message at 03:40 on Sep 9, 2015

Proteus Jones
Feb 28, 2013




I thought I was going cross-eyed, but I think I found your error.

First off I was wrong. The remove is definitely:
Python code:
    link_list.remove(disconnect)
    print(str(disconnect[0]) + " " + str(disconnect[1]))
Secondly, you reversed the elements in the tuple when assigning them to disconnect, so remove method will *never* match the tuple.

Here's the working if, elif, else:
Python code:
    for links in link_list:
        #print(links,file=sys.stderr)
        print(links[0],links[1],enemy,file=sys.stderr)
        if (links[0] == enemy) and (links[1] in gateways):
            disconnect = ( links[1], enemy)
            print("One", disconnect, file=sys.stderr)
            break
        elif (links[1] == enemy) and (links[0] in gateways):
            disconnect = ( links[0], enemy)
            print("Two", disconnect, file = sys.stderr)
            break
        else:
            disconnect = link_list[-1:]
            print("Three",disconnect, file=sys.stderr)

Cingulate
Oct 23, 2012

by Fluffdaddy

BigRedDot posted:

Well, you don't just want a scatter plot. If that's all you want it's about three three lines of python code (including imports). You want a scatter plot with computations and updates all nicely linked to interactive UI. There's lots of potential use-cases, and JS callbacks is one just option, but there is a PR in-flight to allow writing the callbacks in python to be compiled to JS automatically, which will be great. That said, if you want widgets in a just in an IPython notebook, I'd recommend using IPython interactors for now. Those are dead simple and work great, here's an example: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb Bokeh widgets like the ones you are trying to use require a Bokeh server, and I would say hold off on that a month or two since we are in the process of re-writing the thing entirely to make it much better and simpler to use.

Speaking of the server re-write, an interview I did for podcast.__init__ last month just went up, and I speak about the plans quite a bit towards the end: http://ow.ly/RVWLq

EDIT: Also FYI you'll have to run the linked notebook locally. GitHub scrubs all Javascript from it's notebook previews, so things like Bokeh plots and IPython interactors don't show up, and in any case you actually want python to execute in response to the dropdown so that requires a real IPython kernel running.
Thanks. To be honest, right now I feel the best solution for me would be to actually go to Shiny for now and only recommend to my usual practice of near-exclusively working with continuum-provided stuff when the dust has settled.

Gothmog1065
May 14, 2009

flosofl posted:

I thought I was going cross-eyed, but I think I found your error.

First off I was wrong. The remove is definitely:
Python code:
    link_list.remove(disconnect)
    print(str(disconnect[0]) + " " + str(disconnect[1]))
Secondly, you reversed the elements in the tuple when assigning them to disconnect, so remove method will *never* match the tuple.

Here's the working if, elif, else:
Python code:
    for links in link_list:
        #print(links,file=sys.stderr)
        print(links[0],links[1],enemy,file=sys.stderr)
        if (links[0] == enemy) and (links[1] in gateways):
            disconnect = ( links[1], enemy)
            print("One", disconnect, file=sys.stderr)
            break
        elif (links[1] == enemy) and (links[0] in gateways):
            disconnect = ( links[0], enemy)
            print("Two", disconnect, file = sys.stderr)
            break
        else:
            disconnect = link_list[-1:]
            print("Three",disconnect, file=sys.stderr)

I found the problem! Here's a gist of all the code, all of my outputs via the prints in the game, and see if you can spot the problem! It was in disconnect, but it was strange. Plus the out of range error was a stupid on my part, I forgot that basically a list with the value of [(x,y)] is actually a matrix, so the final print was wrong (corrected it, though I could have just done tuple(disconnect) to resolve it possibly).

Gist here!

Hint because I'm an rear end :v: I wasn't setting disconnect as a matrix [(x,y)] in the if/elif, only as a tuple (x,y), so it was breaking poo poo below.

I did end up adding in a 'reverse' function to reverse the x,y because sometimes the link will be one way, and other times it will be another. Just a simple "if the disconnect isn't in link_list, set disconnect as (y,x)". It ran without problems. Could probably be a shitload more efficient, but I guess I did the bare minimum required to solve the problem.

Gothmog1065 fucked around with this message at 15:03 on Sep 9, 2015

Fergus Mac Roich
Nov 5, 2008

Soiled Meat
I don't know how codingame works but my takeaway would be that it's a lot easier to track this stuff down if you can code it so that you can use a debugger(mocking the external data) :v:

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Fergus Mac Roich posted:

I don't know how codingame works but my takeaway would be that it's a lot easier to track this stuff down if you can code it so that you can use a debugger(mocking the external data) :v:

The only feedback you get from their UI is the output of an assert like 'Error: expected "a" but found "b"' but you can do the equivalent of good old printf debugging, though they'll truncate output :rolleyes:

It's really frustrating when you pass all the sample test cases but fail submission cases, which are intentionally different to prevent you from cheating.

Gothmog1065
May 14, 2009

Fergus Mac Roich posted:

I don't know how codingame works but my takeaway would be that it's a lot easier to track this stuff down if you can code it so that you can use a debugger(mocking the external data) :v:

It's a pain in the rear end, that's why I end up using so many print(x,file=sys.stderr) statements so I can make sure the data feed is correct through their UI. That's how I ended up finding the problem I was having (noticing that some of the disconnect data was being saved as (x,y) and some as [(x,y)] ). I have used an external editor and feed (just IDLE), but I've got PyCharm at the house now (may download it here too) and start forcing the errors outside of their environment.

Dominoes
Sep 20, 2007

Stringent posted:

Do yourself a favor and just go ahead and do it in Django. These projects always balloon and you're not gaining that much simplicity from using Flask.

The real use case for Flask is apps that live behind an http server, but are not websites. Anything that might use html, css or JavaScript should probably just be done in Django imo.
Thanks; this ROT concurs with my experience. I'm sticking with Flask on this project because it's nearly done; was able to get the admin and auth system working with Flask-Admin and Flask-Security. It was also a good excuse to learn Bootstrap and Angular JS.

BigRedDot
Mar 6, 2008

Cingulate posted:

Thanks. To be honest, right now I feel the best solution for me would be to actually go to Shiny for now and only recommend to my usual practice of near-exclusively working with continuum-provided stuff when the dust has settled.

Well let's not overstate things: there are lots of use-cases besides yours, that don't involve running python in response to browser UI happenings, for which I would unreservedly recommend Bokeh.

Adbot
ADBOT LOVES YOU

Cingulate
Oct 23, 2012

by Fluffdaddy

BigRedDot posted:

Well let's not overstate things: there are lots of use-cases besides yours, that don't involve running python in response to browser UI happenings, for which I would unreservedly recommend Bokeh.
Sorry - what I meant to say was, for my specific scenario and my specific (very limited) skillset, maybe shiny is more promising for now. I use continuum stuff almost exclusively and my life would be so much harder without conda et al.

  • Locked thread