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
Neslepaks
Sep 3, 2003

Err. Now it worked after all for some reason. Nevermind then :smith:

Adbot
ADBOT LOVES YOU

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

Umbreon posted:

Noted. Thanks guys, I'm gonna give codecademy a try and see how things roll. I've never actually coded/programmed anything before but it always bothered me that I just assumed I couldn't do it without actually giving learning it a fair shake.

Codecademy's free course is for Python2. If you're just signing up for the first time you can definitely get through the Python3 course during the trial period. Otherwise they explain the key differences to you about Python3 during the Python2 course.

NinpoEspiritoSanto
Oct 22, 2013




Treehouse's python content is decent imo.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm late to the party...

Sad Panda posted:

Do people find that inner functions are a good idea?
I'm cleaning up my code and notice that in some of my classes there are functions which are only called from inside other functions in that class. They seem to logically belong to them. What downsides do inner functions have? The only one I can think of is that if you decide that you need to access them directly then you'd have to refactor.

I usually use them to define a traverser for some data structure that is fit for only a specific purpose. This is when the traverser is too long for a single-line lambda.

larper
Apr 9, 2019

Thermopyle posted:

The official tutorial is pretty good.

Really, the best way to get better at any framework is to make lots of stuff with it.

That being said, it sounds like maybe you need help with more than just django? virtualenv's are not just a django thing...

OK, I'll give another crack at the official one. I want to make something very simple to store my bike routes so I can quickly log that I did Ride A or whatever on a certain day.

Umbreon
May 21, 2011

Bundy posted:

Treehouse's python content is decent imo.

Would you happen to know how it compares to codecademy's version?

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
I keep reading cacodemon

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!
A few weeks ago Mozilla introduced Iodide which is some kind of notebook-like clone but for Javascript and I think one of the selling points is that it runs entirely in your browser, no external server needed.

Yesterday they introduced Pyodide which as you probably guessed in Iodide but with Python, and it also runs entirely in your browser.

quote:

Pyodide is an experimental project from Mozilla to create a full Python data science stack that runs entirely in the browser.

Here's an example notebook (and here's another one).


It seems neat at first glance but I can't really imagine a scenario where the running in my browser thing would be something I'd use. If I'm on a laptop then spinning up a jupyter notebook server takes no effort, so for me the useful thing would be if this could be run on like an iPad.

Speaking of iPads, I've been using jupyter notebooks with the "Juno" app and running them on Azure Notebooks and it's pretty great.

Boris Galerkin fucked around with this message at 14:59 on Apr 17, 2019

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Boris Galerkin posted:

A few weeks ago Mozilla introduced Iodide which is some kind of notebook-like clone but for Javascript and I think one of the selling points is that it runs entirely in your browser, no external server needed.

Yesterday they introduced Pyodide which as you probably guessed in Iodide but with Python, and it also runs entirely in your browser.


Here's an example notebook (and here's another one).


It seems neat at first glance but I can't really imagine a scenario where the running in my browser thing would be something I'd use. If I'm on a laptop then spinning up a jupyter notebook server takes no effort, so for me the useful thing would be if this could be run on like an iPad.

Speaking of iPads, I've been using jupyter notebooks with the "Juno" app and running them on Azure Notebooks and it's pretty great.

Why code on an ipad?

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!
I don’t really, but I like being able to open up a notebook and redraw a figure or something. The auto completion that you get from the notebook itself is pretty good and not annoying. I guess I should mention that I’m talking about an iPad with a physical keyboard, which makes all the difference.

Tayter Swift
Nov 18, 2002

Pillbug
Sometimes you're on a train and can't be bothered to whip out a keyboard :shrug:

I do find it rather annoying that the shift key in Juno is a toggle instead of a single letter.

Spaseman
Aug 26, 2007

I'm a Securitron
RobCo security model 2060-B.
If you ever see any of my brothers tell them Victor says howdy.
Fallen Rib
I'm messing around with Python and tkinter and I'm wondering if someone can explain why when I run my script the text "third" appears in the text box despite only declaring the variable and not actually using it?

code:
from tkinter import *

class App:
    def __init__(self, master):
        self.frame = Frame(master)
        self.frame.grid()

        self.text = Text(self.frame, height=8, width=20)
        self.text.grid()

        self.button = Button(self.frame, text="quit", command=self.frame.quit)
        self.button.grid(row=2, padx=1, pady=1)

        self.text.insert(END, "first")
        self.text.insert(END, "second")
        vvv = self.text.insert(END, "third")

        self.button2 = Button(self.frame, text="add text", command=self.frame.quit)
        self.button2.grid()
            

    def create_button(self, row, text, command):
        self.button = Button(self.frame, text=text, command=command)
        self.button.grid(row=row, padx=1)

    def game_start(self):
        self.T = Text(self.frame, height=8, width=90)
        self.T.grid()
        self.button = Button(self.frame, text="123", command=self.T.insert(END, "gggg"))
        self.button.grid(row=4, padx=1)
      
    def insert_text(self, fill_text):
        self.T.insert(END, fill_text)

    def game_text(self):
        self.quote1 = ("rrrrrrrrrrrrrrrrr")
        self.quote2 = ("ffffffffffffffffffffffff")     

root = Tk()

root.geometry("500x500")
root.resizable(0,0)
root.title("HELOO")

app = App(root)

root.mainloop()
root.destroy()

Cosa Nostra Aetate
Jan 1, 2019

Spaseman posted:

I'm messing around with Python and tkinter and I'm wondering if someone can explain why when I run my script the text "third" appears in the text box despite only declaring the variable and not actually using it?

code:
from tkinter import *

class App:
    def __init__(self, master):
        self.frame = Frame(master)
        self.frame.grid()

        self.text = Text(self.frame, height=8, width=20)
        self.text.grid()

        self.button = Button(self.frame, text="quit", command=self.frame.quit)
        self.button.grid(row=2, padx=1, pady=1)

        self.text.insert(END, "first")
        self.text.insert(END, "second")
        vvv = self.text.insert(END, "third")

        self.button2 = Button(self.frame, text="add text", command=self.frame.quit)
        self.button2.grid()
            

    def create_button(self, row, text, command):
        self.button = Button(self.frame, text=text, command=command)
        self.button.grid(row=row, padx=1)

    def game_start(self):
        self.T = Text(self.frame, height=8, width=90)
        self.T.grid()
        self.button = Button(self.frame, text="123", command=self.T.insert(END, "gggg"))
        self.button.grid(row=4, padx=1)
      
    def insert_text(self, fill_text):
        self.T.insert(END, fill_text)

    def game_text(self):
        self.quote1 = ("rrrrrrrrrrrrrrrrr")
        self.quote2 = ("ffffffffffffffffffffffff")     

root = Tk()

root.geometry("500x500")
root.resizable(0,0)
root.title("HELOO")

app = App(root)

root.mainloop()
root.destroy()

Print the value of vvv. It's probably None, because you called a method to insert the text, and didn't store the text.

Dr Subterfuge
Aug 31, 2005

TIME TO ROC N' ROLL
All three of those text.inserts are evaluated the same way. The third one is just assigning its return value, which is probably None, to vvv.

YanniRotten
Apr 3, 2010

We're so pretty,
oh so pretty
Oof anybody try to throw a linter into an existing (super messy) set of projects? Some of my team is like 'yeah pylint me baby' but this seems like it would hurt pretty bad and we'd have config drift unless we solved that problem.

This is going to be a 'lint all changed files after X grandfathered commit' implementation both at commit time and on the build server. I do want to do better than barebones flake8 (mostly PEP8 and bad syntax police) but yikes at the current pylint output, even with a bunch of poo poo ignored.

Is flake8 a good baby step to make in this situation? pylint feels like a full blown can of worms.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Our approach for awful projects like that was to say if you touched a file in a change you fixed it then. This made the up front lift small, but could cause small changes to take longer. It was worth it and eventually only 10% of files which were never touched remained and somebody just went in and fixed them later.

This is tricky with CI though since you can only run the lint against files changed in the commit or it'll fail for you constantly.

YanniRotten
Apr 3, 2010

We're so pretty,
oh so pretty

necrotic posted:

This is tricky with CI though since you can only run the lint against files changed in the commit or it'll fail for you constantly.

Fortunately (I mean, sort of, maybe a bad idea) TeamCity does have a check out mode where your project looks like a real git clone with .git metadata instead it just being a bag of files. So it should be possible to figure this stuff out.

larper
Apr 9, 2019

Boris Galerkin posted:

A few weeks ago Mozilla introduced Iodide which is some kind of notebook-like clone but for Javascript and I think one of the selling points is that it runs entirely in your browser, no external server needed.

Yesterday they introduced Pyodide which as you probably guessed in Iodide but with Python, and it also runs entirely in your browser.


Here's an example notebook (and here's another one).


It seems neat at first glance but I can't really imagine a scenario where the running in my browser thing would be something I'd use. If I'm on a laptop then spinning up a jupyter notebook server takes no effort, so for me the useful thing would be if this could be run on like an iPad.

I guess it's like, one step further than Jupyter in portability... to use Jupyter you have to have a giant stack that takes forever to install on a slow machine. Im sure this thing would be slow in Firefox, but its entirely based off the internet and needs no stack running on the server, or can be zipped and sent in email or whatever

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies

necrotic posted:

Our approach for awful projects like that was to say if you touched a file in a change you fixed it then. This made the up front lift small, but could cause small changes to take longer. It was worth it and eventually only 10% of files which were never touched remained and somebody just went in and fixed them later.

This is tricky with CI though since you can only run the lint against files changed in the commit or it'll fail for you constantly.

Yeah, this is what I've done for large projects that hadn't yet been linted continuously. Just defined each file individually within whatever the ignore file format is (.flake8 -> exlude=) and then just over time submit a PR that fixes all style issues in a file and remove it from that list. Prevents any new files from not following the style, and then can overtime fix up old code. I do prefer to not mix PRs of bugfixes/features with PRs fixing style changes as that just leads to it being a pain to actually properly review a change amongst all the noise.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yeah, mixing lint fixes in with a PR can get messy. We tried to enforce a "first commit has the lint fixes" which worked most of the time (you could review all but that commit easily enough), but sometimes a mid-PR change would then touch another file.

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde

Boris Galerkin posted:

It seems neat at first glance but I can't really imagine a scenario where the running in my browser thing would be something I'd use. If I'm on a laptop then spinning up a jupyter notebook server takes no effort, so for me the useful thing would be if this could be run on like an iPad.

Everything that lets Javascript be a thing of the past like ruby, perl or php is welcome.

Thermopyle
Jul 1, 2003

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

modern JS is pretty good and new PEP's are lifting a lot of ideas from it and its cousin TypeScript.

But, python won't replace JS in the browser because stuff like V8 has bajillions of dollars of optimization put in to it (node is faster than python), and downloading the python interpreter and whatever modules for every page and translating calls to the DOM is just going to have too large of a performance hit.

That being said, I'd much rather write python.

Umbreon
May 21, 2011
Would you guys say the codecademy membership is worth it? The price looks pretty steep for a monthly charge, but I've actually been enjoying the lessons so far for python 3

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

Umbreon posted:

Would you guys say the codecademy membership is worth it? The price looks pretty steep for a monthly charge, but I've actually been enjoying the lessons so far for python 3

I'm not sure what the point of a longer term sub is. You'll finish the Python course and then what? Sure they have SQL and whatever else but if you're wanting to focus on Python then what else do they have that you'd use?

Umbreon
May 21, 2011

Sad Panda posted:

I'm not sure what the point of a longer term sub is. You'll finish the Python course and then what? Sure they have SQL and whatever else but if you're wanting to focus on Python then what else do they have that you'd use?

Oh I agree, I'm only asking about the monthly sub, I wouldn't get anything longer than that. I'm saying that even $40 a month feels really expensive for something like this, I just want to make sure it's worth it.

(as things stand, it feels like it's worth it, but I've only done the first few lessons so I want to make sure it doesn't lower in quality later on or anything like that)

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Umbreon posted:

Oh I agree, I'm only asking about the monthly sub, I wouldn't get anything longer than that. I'm saying that even $40 a month feels really expensive for something like this, I just want to make sure it's worth it.

(as things stand, it feels like it's worth it, but I've only done the first few lessons so I want to make sure it doesn't lower in quality later on or anything like that)

If you're using it to do personal projects maybe its a little costly...I'd probably just move on to projects from there. (e.g. if you want to learn python to do data science/deep learning, go here, it is free: https://course.fast.ai/videos/?lesson=1)

If you're trying to do your current job better get your company to pay for it
If you're trying to do a new job it is dirt cheap relative to a code bootcamp or other more formal training scenario

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
What's the suggest structure for tests for a module that is not installable? I've got the standard structure of:
pre:
pkg/
  __init__.py
  module_1.py
tests/
  __init__.py
  test_module_1.py
where test_module_1.py at the top has a line to import pkg.module_1.

and so I can use
code:
python -m unittest discover
and it works totally fine, but if I try and do
code:
python tests/test_module_1.py
(or the equivalent command through python -m unittest) it will complain about how it cannot import pkg.module_1. Is the suggested fix here to use sys to insert the path to the package or is there something I'm missing here? Would pytest offer some sort of solution?

Neslepaks
Sep 3, 2003

I'd suggest invoking through pytest instead yeah. Tends to be less finicky that way.

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies

Neslepaks posted:

I'd suggest invoking through pytest instead yeah. Tends to be less finicky that way.
I guess a follow-up question would be how does pytest under the hood resolve things so that I can just do `pytest tests/test_module_1.py` or even just `pytest test_module_1.py` and it will know what `pkg` is and is importable?

e: Actually, I think I found why I'm so confused on the manner. Using the example from above, why it is that unittest seems to choke if I do an import like this:
code:
import pkg

def test_something():
    pkg.module_1.do_something()
and it throws an error about not being able to find pkg.module_1, but if I just import pkg.module_1 it works fine. Not sure what that's about, but now at least things are working as I'd expect.

Master_Odin fucked around with this message at 20:14 on Apr 21, 2019

QuarkJets
Sep 8, 2008

Probably relevant, sounds like you may need to remove __init__.py

https://stackoverflow.com/questions/41748464/pytest-cannot-import-module-while-python-can/41752043

KICK BAMA KICK
Mar 2, 2009

A simple dict mapping strings to strings (can guarantee they're short, alphanumeric, no whitespace) that I want to read/write from disk -- is pickle the best option or would you rather write it as a text file? Few hundred entries at most, accessed/modified a only few times a day. Portability between implementations and platforms would be a huge plus.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

KICK BAMA KICK posted:

A simple dict mapping strings to strings (can guarantee they're short, alphanumeric, no whitespace) that I want to read/write from disk -- is pickle the best option or would you rather write it as a text file? Few hundred entries at most, accessed/modified a only few times a day. Portability between implementations and platforms would be a huge plus.

I do a lot of pickle reading/writing and csv reading/writing with the pandas implementation of each. Pickle is an order of magnitude faster, would take a pickle every time. (Bonus that it handles mixed data types)

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

KICK BAMA KICK posted:

A simple dict mapping strings to strings (can guarantee they're short, alphanumeric, no whitespace) that I want to read/write from disk -- is pickle the best option or would you rather write it as a text file? Few hundred entries at most, accessed/modified a only few times a day. Portability between implementations and platforms would be a huge plus.
shelve exists.

quote:

A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings.

Thermopyle
Jul 1, 2003

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

I'd probably use json. Easy to read by "hand" if need be.

NinpoEspiritoSanto
Oct 22, 2013




Thermopyle posted:

I'd probably use json. Easy to read by "hand" if need be.

Seconding this, why use something as awful as pickle when json exists?

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!
I get the impression that I should pickle an object if and only if I’m too lazy to create a method to serialize it to a dict (and then save as json). Is that accurate? Never dealt with pickles before.

Wallet
Jun 19, 2006

Bundy posted:

Seconding this, why use something as awful as pickle when json exists?

This is what I was thinking as I read that, but then I thought maybe they know something I don't. A simple dictionary is exactly the kind of case where json is super convenient, particularly if you want it to be easy to use with whatever else.

punished milkman
Dec 5, 2018

would have won
I think reading/writing pickle objects is marginally faster than text files like JSON, so if that's a concern pickling is probably superior. Otherwise yeah working with JSON files is much nicer in every way.

Tayter Swift
Nov 18, 2002

Pillbug
Why are we discussing performance for a task that will take a couple milliseconds a day :confused:

Adbot
ADBOT LOVES YOU

mbt
Aug 13, 2012

Lol they even said in their initial question it would have a few hundred values at most

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