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
FoiledAgain
May 6, 2007

Dominoes posted:

Is there a trick to getting matplotlib plots to not freeze the GUI?

Threading doesn’t work.

I can't get plt.draw() to work. (still freezes the GUI)

plt.ion() prevents the freezing, but also prevents me from closing the plot window, or opening additional ones.

For tkinter, the trick is to use plt.save(), then load that image onto a Canvas object. Don't use .show().

Adbot
ADBOT LOVES YOU

SurgicalOntologist
Jun 17, 2004


You're close. First of all, a property must return something. It should be thought of as closer to an attribute than a method.

Python code:
class MyClass:
    def __init__():
        self.actual_message = 'hi'

    @property
    def message(self):
        return self.actual_message

my_instance = MyClass()
print(my_instance.message)
Secondly, in the above, message a "getter", calling it gets the property message (which really just mirrors hidden_message, but the user doesn't have to know that). You can also define a "setter", as so:

Python code:
class MyClass:
    def __init__():
        self.actual_message = 'hi'

    @property
    def message(self):
        return self.actual_message

    @message.setter
    def message(self, value):
        self.actual_message = value

my_instance = MyClass()
print(my_instance.message)
my_instance.message = 'bye'
print(my_instance.message)
Why might you do this? Maybe you want to trigger some behavior every time an attribute is set (or accessed), or make sure it's not of bounds. Then you should turn that property into an attribute with a setter method. Often you don't need the setter, you'll just have the getter, which acts like an attribute but is actually calculated from other attributes. If you had a Polygon class, you might have properties like circumference, area, centroid, etc. that can be accessed as if they were attributes but are really calculated as needed from the list of points. (and since they don't have a corresponding setter, they can't be directly set to a new value)

SurgicalOntologist fucked around with this message at 00:19 on Nov 22, 2013

Haystack
Jan 23, 2005





I've always rolled with the default python installations. However, I did have to spend quite a bit of time learning and fighting with easy_install, pip and compiler nonsense. It was instructive, but I'm not sure if I would recommend it if it could be avoided.




Both of your examples will throw attribute exceptions, because my_instance.hi doesn't get set until my_method gets called (with or without the property).

Properties are most useful as a way of tucking away calculations based on other members of an object. A trivial example:

Python code:
class Person(object):
    def __init__(self, first_name, last_name='', middle_names=''):
        self.first_name = first_name
        self.last_name = last_name
        self.middle_names = middle_names
    @property
    full_name(self):
        return self.first_name + " " + self.middle_names + " " + self.last_name 

bob = Person('Bob', 'Howard')
print(bob.full_name) # "Bob  Howard"   
It's basically a way for a data-oriented calculation to look and act like a normal attribute. To that end, the property.setter() syntax lets you control what happens when someone tries to assign something to your property. For instance, you could make bob.full_name = "Andy Newstrom" actually set first_name and last_name correctly

Haystack fucked around with this message at 00:41 on Nov 22, 2013

suffix
Jul 27, 2013

Wheeee!

Dominoes posted:

What's the deal with @property? PyCharm suggests adding this decorator to methods that have no arguments other than 'self'. As a result, the method names are then called as class variables instead of methods, ie without the (). So, it's a way of saying "this is a class variable that changes automatically".

It seems like a straightforward syntax alteration, but I'm confused because the docs and other material online are pretty complicated, and talk about getters and setters (without explaining what they are - I assumed that might be terminology for a class method that doesn’t use property, but there's apparently '@x.setter' syntax too), and a lot of other stuff that's not the simple explanation I posted above.

Okay, so first: properties and getters and setters. As you may know, in Java, you have class properties, like a "public double width;". But you should never access those from outside the class, because what if you suddenly wanted to calculate the width as "area / height"? Or what if you wanted to make sure that width is always positive?! What if??!
So instead you make a "private double width;", and a "public double getWidth()" and a "public void setWidth(double width)", and those methods are your getters/setters. And you probably have an IDE that automatically generates getters and setters, because 99% of the time they're just boilerplate around a private property. For a read-only property, you may have a "public double getArea()" but not a corresponding "setArea()".

Now writing all those setter and getter methods is unpythonic, because YAGNI. So in Python, you just assume that everything that looks like a property is a property. So instead of myrectangle.setWidth(100), you'll write myrectangle.width = 100.

But now What If you wanted to change the internals of Rectangle to store the height and area instead? Well, in Python, you can give Rectangle a 'width' property to define what myrectangle.width = 100 really means.
So you'll write
Python code:
def getWidth(self): return self._width
def setWidth(self, width): self._width = width
width = property(getWidth, setWidth)
and now "myrectangle.width = 100" is the same as "myrectangle.setWidth(100)"

Or you could write
Python code:
@property
def width(self): return self._width
@width.setter
def setWidth(self, width): self._width = width
instead, it's just a slightly nicer way of writing it since you don't have to say the name of the methods twice.

So now the onus on you, the developer, to determine what should be a "method" and what should be a "property". Obviously .doComplicatedStuff(a, b, c) should be a method, and .width should probably be a property, but what about the stuff in between?
It's not an exact science, but generally a 'property' should be cheap to access (O(1) at least), reading it should have no side effects, and it should not change unexpectedly.
If it takes arguments, if it can take some time to calculate, or if the result can change for reasons outside the control of the programmer, it should probably be a method.

Most importantly, don't write code before it's needed. If it feels like the width of a rectangle should be an attribute you access directly with "myrectangle.width", do that, and if it turns out that you need to check that width is always positive, add a setter later using @property. The point of @property is first and foremost to avoid writing a million get*()/set*() methods you don't really need.

Bloodborne
Sep 24, 2008

Thermopyle posted:

One of you is saying on the new OP document to not suggest Windows users download the python.org Windows version but to instead download a Windows-specific distribution like...well like, I don't know what. But anyway...

My personal feelings on it are that when I was doing dev work on Windows I always preferred to use the official distribution and install whatever packages I wanted or needed. However, I must say that I didn't spend a lot of time evaluating other options as the whole idea of it just rubbed me the wrong way.

Does anyone have any thoughts about whether recommending Windows users use something other than the official distribution is a good idea?

In particular I'd like some thoughts from non-scientific users whom I think probably have different requirements than your average beginner. They're almost always whom I see talking about alternative distributions...

My thoughts as a total programming and Python newbee is that I would rather download the official package for the OS I'm working on, and learn the ins and outs via a text editor and then passing it through an interpreter like Powershell. Granted this is all I know based on LPTHW but it makes total sense to me. All the other things I can dabble in and gain a preference for AFTER I've gotten a good foundation and basic hold on concepts and the language.

Dominoes
Sep 20, 2007

Thanks for the info on properties; Going through my code to see where they're appropriate.


Dominoes posted:

I'm also looking for info on changing the plot window size (without having to adjust it with the mouse after it opens). The guides show using figure() objects, but I'm trying to use a plot.
Found the solution syntax on the Matplotlib site: here:
Python code:
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(111)
ax.plot(x, y)
plt.show()

Dominoes fucked around with this message at 03:07 on Nov 22, 2013

QuarkJets
Sep 8, 2008

Thermopyle posted:

One of you is saying on the new OP document to not suggest Windows users download the python.org Windows version but to instead download a Windows-specific distribution like...well like, I don't know what. But anyway...

My personal feelings on it are that when I was doing dev work on Windows I always preferred to use the official distribution and install whatever packages I wanted or needed. However, I must say that I didn't spend a lot of time evaluating other options as the whole idea of it just rubbed me the wrong way.

Does anyone have any thoughts about whether recommending Windows users use something other than the official distribution is a good idea?

In particular I'd like some thoughts from non-scientific users whom I think probably have different requirements than your average beginner. They're almost always whom I see talking about alternative distributions...

It wasn't me, but I agree with the comment.

I'd suggest Anaconda or Pythonxy (they're both pretty similar) over building your own environment. It's going to significantly easier to install and use those than to install all of the individual libraries that you might need, plus they come with nice IDEs for you to develop in. You are getting the official python.org distribution, but you're also getting a whole lot more. The IDEs alone make this a great option.

Dominoes posted:

I prefer the official version on Windows by default, from the perspective of a beginner with no interest in scientific computing, and later, as someone who uses it.

There's no need to add scientific packages by default if you have no intention of using them. If you need them, the LFCI website makes installing them very easy.

I get the impression that the target market for pre-packaged versions are scientists who have no interest in learning more programming concepts than they need to.

The target isn't just scientists, it's for everyone who doesn't want to have to gently caress around with installing and customizing their Python environment on an OS that isn't designed for that kind of thing. If you haven't done it before, setting up Python on Windows is a pain in the rear end. These all-in-one packages streamline the process and let you immediately start writing code and seeing results without having to mess with environmental variables or any other installations, even.

Scientific libraries are a tiny piece of the pie that you get from Anaconda/Pythonxy/others. They come with extra GUI libraries, web development libraries, miscellaneous API libraries, scientific libraries, etc. They also come with some very nice IDEs that you might never get to see otherwise (a new user might end up using Notepad and the Windows command line or something, which would be horrible by comparison).

Some people might prefer the piecemeal build-your-own of going through python.org and then downloading and installing all of the libraries that you need, but for most people that's not going to be the best option in a Windows environment.

Thermopyle
Jul 1, 2003

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

QuarkJets posted:

If you haven't done it before, setting up Python on Windows is a pain in the rear end. These all-in-one packages streamline the process and let you immediately start writing code and seeing results without having to mess with environmental variables or any other installations, even.

Scientific libraries are a tiny piece of the pie that you get from Anaconda/Pythonxy/others. They come with extra GUI libraries, web development libraries, miscellaneous API libraries, scientific libraries, etc. They also come with some very nice IDEs that you might never get to see otherwise (a new user might end up using Notepad and the Windows command line or something, which would be horrible by comparison).

Some people might prefer the piecemeal build-your-own of going through python.org and then downloading and installing all of the libraries that you need, but for most people that's not going to be the best option in a Windows environment.

I'm not convinced.

I don't like the idea of having all those libraries installed. It just rubs me the wrong way. The idea of packaged IDE's turns me off of them even more. I always try to default to what is going to have the most support with my Googlin' and these specialized distributions ring my alarm bells in that regard.

Now that I've said that, I moved to linux for my development purposes a long time ago because library management was much easier...but my understanding is that it's not too bad on Windows any more.

I'll make mention of their availability in the OP alongside python.org.

Actually, as I'm typing, I realized that I might mention in the OP what I'm doing nowadays. I switched back to Windows for My Gamez, but pretty much always have Ubuntu running via VMWare on two of my three monitors for development. It's pretty much seamless.

Dominoes
Sep 20, 2007

edit: nvm

Dominoes fucked around with this message at 08:10 on Nov 22, 2013

BigRedDot
Mar 6, 2008

Thermopyle posted:

I'm not convinced.

I don't like the idea of having all those libraries installed. It just rubs me the wrong way. The idea of packaged IDE's turns me off of them even more. I always try to default to what is going to have the most support with my Googlin' and these specialized distributions ring my alarm bells in that regard.

Now that I've said that, I moved to linux for my development purposes a long time ago because library management was much easier...but my understanding is that it's not too bad on Windows any more.

I'll make mention of their availability in the OP alongside python.org.

Actually, as I'm typing, I realized that I might mention in the OP what I'm doing nowadays. I switched back to Windows for My Gamez, but pretty much always have Ubuntu running via VMWare on two of my three monitors for development. It's pretty much seamless.

If you use Anaconda you are free to create as many environments with nothing but python as you like: "conda create -n mybarrenenv python=2.7" No other packages. On the other hand, lots of other packages are easily installable, from us, from PyPI, from binstar, if you think mucking with C extension builds on Windows is a crappy hobby (it is).

BigRedDot fucked around with this message at 08:28 on Nov 22, 2013

Jewel
May 2, 2009

Or you could just get python from the main site and run IDLE v:shobon:v

I agree with Thermopyle by far, beginners don't need an IDE at all, especially not when you're starting out coding for the first time ever. If you're going from something else like C++ to python, they also don't need a big package of stuff either because they won't be new to the concept of finding an IDE/modules.

QuarkJets
Sep 8, 2008

Thermopyle posted:

I'm not convinced.

I don't like the idea of having all those libraries installed. It just rubs me the wrong way. The idea of packaged IDE's turns me off of them even more. I always try to default to what is going to have the most support with my Googlin' and these specialized distributions ring my alarm bells in that regard.

Why? It's a single self-contained package as far as Windows is concerned, and you're free to remove it whenever you want. They're also self-contained Python package managers, so you can add or remove whatever modules you want without increasing the complexity of your environment.

And I also think that being given a nice IDE with a console is a huge quality-of-life improvement for new Python users. That's probably why even the python.org installation comes with one, I just don't think that it's very good. What would you suggest using instead of an IDE, Notepad++ and the Windows command line or something?

e: I also don't understand what you mean by "specialized distribution". It's not like they've changed any of the modules, they're just bundling a bunch of things together. Googling for answers is going to be the same regardless

QuarkJets fucked around with this message at 11:12 on Nov 22, 2013

Dren
Jan 5, 2001

Pillbug
When I suggest python to windows people I suggest they get anaconda. It is much easier than setting up the python.org version. Oh yeah, and windows people love IDEs.

Dominoes, don't feel like you need to go run out and add @property to everything. @property is analogous to getter/setters in java and I think the main reason it is in python is to make java people feel comfortable. In python (and even in java) it is perfectly fine to leave member variables exposed for access by the user if that is what you need to do. Heck, in python the user can always get to them if they want. If you later decide you want to lazy init that value you can make a getter for it with @property. Otherwise, don't bother with @property it is usually extra cruft.

Dominoes
Sep 20, 2007

QuarkJets posted:

And I also think that being given a nice IDE with a console is a huge quality-of-life improvement for new Python users. That's probably why even the python.org installation comes with one, I just don't think that it's very good. What would you suggest using instead of an IDE, Notepad++ and the Windows command line or something?
Yes. It's straightforward, and won't overwhelm or confuse someone who's new. When you're learning, new concepts blur together; it's easy to lose sight of what the core concepts are when you introduce too many things at once. It's not a big deal either way, but this is why I'd prefer recommending a clean Python install. I could see someone new not grasping the concept of where Python ends and Anaconda starts, what are quirks for setting up the IDE and what are language concepts etc. I recently tried and failed miserably at a Django tutorial, because it introduced virtual environments, versioning, databases, PaaS, third-party tools etc at once, without making it clear what was actually Django. Not a perfect comparison, but I think it applies.

Dren posted:

Dominoes, don't feel like you need to go run out and add @property to everything. @property is analogous to getter/setters in java and I think the main reason it is in python is to make java people feel comfortable. In python (and even in java) it is perfectly fine to leave member variables exposed for access by the user if that is what you need to do. Heck, in python the user can always get to them if they want. If you later decide you want to lazy init that value you can make a getter for it with @property. Otherwise, don't bother with @property it is usually extra cruft.
Would it be appropriate for cases like this?
Python code:
def last(self):
    return s.PROVIDER_REAL.quote(self.symbol, 'last')
stock.last() acts like an attribute that's value changes whenever called. The main difference is the addition of @property, and the removal of parenthesis when it's called. I feel like it might be worth it to get rid of the parenthesis if I call it a lot, since the added clutter's a pain if line's shared with other parentheses. However, hiding the fact that the value performs calculations (and an HTTP request in this case) when calling it may be a bad thing; explicit is better than implicit. The user would never set this value.

Dominoes fucked around with this message at 16:32 on Nov 22, 2013

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Definitely never use @property for something that sends a HTTP request.

Munkeymon
Aug 14, 2003

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



Thermopyle posted:

One of you is saying on the new OP document to not suggest Windows users download the python.org Windows version but to instead download a Windows-specific distribution like...well like, I don't know what. But anyway...

My personal feelings on it are that when I was doing dev work on Windows I always preferred to use the official distribution and install whatever packages I wanted or needed. However, I must say that I didn't spend a lot of time evaluating other options as the whole idea of it just rubbed me the wrong way.

Does anyone have any thoughts about whether recommending Windows users use something other than the official distribution is a good idea?

In particular I'd like some thoughts from non-scientific users whom I think probably have different requirements than your average beginner. They're almost always whom I see talking about alternative distributions...

I'm a non-scientific user and the last two times I've set up Python on a Windows machine I used Anaconda because :effort: basically. I didn't even know it had an IDE involved - I just didn't want to gently caress with getting all those packages individually, which is annoying on Windows because you can't just type sudo apt-get install some-library like you can on *nix.

Dren
Jan 5, 2001

Pillbug

Dominoes posted:

Would it be appropriate for cases like this?
Python code:
def last(self):
    return s.PROVIDER_REAL.quote(self.symbol, 'last')
stock.last() acts like an attribute that's value changes whenever called. The main difference is the addition of @property, and the removal of parenthesis when it's called. I feel like it might be worth it to get rid of the parenthesis if I call it a lot, since the added clutter's a pain if line's shared with other parentheses. However, hiding the fact that the value performs calculations (and an HTTP request in this case) when calling it may be a bad thing; explicit is better than implicit. The user would never set this value.

You can look at stock.last() as a property if you really want to. In terms of functionality I see no reason for it to be a property or a method. However, I would leave it as a method because I expect members without parentheses in python to be instances of objects, not function calls with side-effects like an HTTP request.

suffix sarcastically laid out the case for getter/setters in java in his post:

suffix posted:

Okay, so first: properties and getters and setters. As you may know, in Java, you have class properties, like a "public double width;". But you should never access those from outside the class, because what if you suddenly wanted to calculate the width as "area / height"? Or what if you wanted to make sure that width is always positive?! What if??!

The case for use of getter/setters in Java is that you might need to do something beyond simply returning the underlying member and if you ever have to switch to that mode you'll have to refactor all of your code to be a function call instead of referring to an actual object/primitive. So to avoid the potential future refactoring, someone recommended that objects in java get a poo poo ton of boilerplate getter/setter code and everyone listened to that guy.

@property in python allows for neatly skirting the issue of refactoring if there is ever a need to do more than simple object access. Switch to a function, decorate with @property, and user code is none the wiser. Imo, this is the only legitimate use-case for @property. But even in this case I would rather switch to using a function and force users to refactor than use @property.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Dren posted:

You can look at stock.last() as a property if you really want to. In terms of functionality I see no reason for it to be a property or a method. However, I would leave it as a method because I expect members without parentheses in python to be instances of objects, not function calls with side-effects like an HTTP request.

suffix sarcastically laid out the case for getter/setters in java in his post:


The case for use of getter/setters in Java is that you might need to do something beyond simply returning the underlying member and if you ever have to switch to that mode you'll have to refactor all of your code to be a function call instead of referring to an actual object/primitive. So to avoid the potential future refactoring, someone recommended that objects in java get a poo poo ton of boilerplate getter/setter code and everyone listened to that guy.

@property in python allows for neatly skirting the issue of refactoring if there is ever a need to do more than simple object access. Switch to a function, decorate with @property, and user code is none the wiser. Imo, this is the only legitimate use-case for @property. But even in this case I would rather switch to using a function and force users to refactor than use @property.
The danger is in the expectation that property access is instantaneous, and doesn't require any expensive computation. Properties are fine when this attribute is preserved, but things get messy if an end-user of the library expects an immediate result and end up with some O(n) monstrosity crawling their data structure behind the scenes.

Dren
Jan 5, 2001

Pillbug

Misogynist posted:

The danger is in the expectation that property access is instantaneous, and doesn't require any expensive computation. Properties are fine when this attribute is preserved, but things get messy if an end-user of the library expects an immediate result and end up with some O(n) monstrosity crawling their data structure behind the scenes.

This is another fine reason to not use properties.

Dominoes, I forgot to answer your question about matplotlib figures by pointing you at the matplotlib user's guide. Reading the "Artist tutorial" section will tell you what you need to know about how figures and axes relate. If you need to do more complicated layout stuff, especially stuff with the various coordinate systems, keep the user's guide handy and at least skim most of it. The matplotlib API docs are ok but the user's guide ties together the parts of the API that would otherwise seem disparate.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
Is there a pypy installer for windows?

Or even a chocolaty package

breaks
May 12, 2001

Dren posted:

In terms of functionality I see no reason for it to be a property or a method.

What should it be if not one or the other?

Dren
Jan 5, 2001

Pillbug

breaks posted:

What should it be if not one or the other?

I meant one over the other.

Thermopyle
Jul 1, 2003

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

I'm curious about this distributions-vs-python.org thing, so I'm in the middle of spinning up some VMs to test poo poo out.

I haven't done any Python on Windows in a long time, and I've barely touched any of the Windows-specific distributions, so I'm going to get familiar with all the options here...

tractor fanatic
Sep 9, 2005

Pillbug
Two quick questions:

If I wanted to print every letter in the alphabet, how would I do it? I can do this:

Python code:
for a in range(ord('a'), ord('z')+1):
    print chr(a)
But maybe there's a more pythonic way?

Also, I wanted to select some elements from inside a dictionary into a tuple. I have this:

Python code:
def select(dicty, *args):
	return tuple([dicty[a] for a in args])
a, b, c = select(dic, 'x', 'y', 'z')
But is there already a function that does this, or a language feature?

FoiledAgain
May 6, 2007

tractor fanatic posted:

Two quick questions:

If I wanted to print every letter in the alphabet, how would I do it? I can do this:

Python code:
for a in range(ord('a'), ord('z')+1):
    print chr(a)
But maybe there's a more pythonic way?


Import the string module and use it, e.g:
code:
import string
print string.ascii_lowercase

quote:

Also, I wanted to select some elements from inside a dictionary into a tuple. I have this:

Python code:
def select(dicty, *args):
	return tuple([dicty[a] for a in args])
a, b, c = select(dic, 'x', 'y', 'z')

Why don't you just do this as a,b,c = dict['x'],dict['y'],dict['z']? Do you need a function for this? You aren't really making a tuple anyway, you're unpacking it into three different variables.

FoiledAgain fucked around with this message at 06:38 on Nov 23, 2013

QuarkJets
Sep 8, 2008

Dominoes posted:

Yes. It's straightforward, and won't overwhelm or confuse someone who's new. When you're learning, new concepts blur together; it's easy to lose sight of what the core concepts are when you introduce too many things at once. It's not a big deal either way, but this is why I'd prefer recommending a clean Python install. I could see someone new not grasping the concept of where Python ends and Anaconda starts, what are quirks for setting up the IDE and what are language concepts etc. I recently tried and failed miserably at a Django tutorial, because it introduced virtual environments, versioning, databases, PaaS, third-party tools etc at once, without making it clear what was actually Django. Not a perfect comparison, but I think it applies.

Python.org and Anaconda and Pythonxy each come with one or more IDEs, the Python.org IDE (IDLE) is just a bit too bare bones to be useful, in my opinion. That said, the Windows command line is the worst of all options and I don't know how you can seriously suggest that it's what new users should use.

Thermopyle posted:

I'm curious about this distributions-vs-python.org thing, so I'm in the middle of spinning up some VMs to test poo poo out.

I haven't done any Python on Windows in a long time, and I've barely touched any of the Windows-specific distributions, so I'm going to get familiar with all the options here...

I think that's a good idea.

Thermopyle
Jul 1, 2003

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

QuarkJets posted:

Python.org and Anaconda and Pythonxy each come with one or more IDEs, the Python.org IDE (IDLE) is just a bit too bare bones to be useful, in my opinion. That said, the Windows command line is the worst of all options and I don't know how you can seriously suggest that it's what new users should use.

I think that's exactly what new users should use, but I think its quite arguable.

Dominoes
Sep 20, 2007

I've been storing historical stock data in a 130mb and growing json file, which I import/export from a python dict, which stays in memory while my program's running. Info is stored in the format {symbols: {dates: {attributes: values}}} . Loading the file is slow, and saving it is slower.

Would I benefit from a different storage method? Does SQLite sound appropriate for this?

The names of the attributes directly affect file size and performance. I've taken to using a shorthand, like replacing 'close price' with 'c'. This seems to indicate that JSON may not be an appropriate format.

QuarkJets
Sep 8, 2008

Dominoes posted:

I've been storing historical stock data in a 130mb and growing json file, which I import/export from a python dict, which stays in memory while my program's running. Info is stored in the format {symbols: {dates: {attributes: values}}} . Loading the file is slow, and saving it is slower.

Would I benefit from a different storage method? Does SQLite sound appropriate for this?

The names of the attributes directly affect file size and performance. I've taken to using a shorthand, like replacing 'close price' with 'c'. This seems to indicate that JSON may not be an appropriate format.

This is definitely a situation where an SQLite database would be appropriate. If you ever start to think about deploying your tool onto a website or across a large number of simultaneous users or something then you might need to move up to some sort of enterprise database

QuarkJets
Sep 8, 2008

Thermopyle posted:

I think that's exactly what new users should use, but I think its quite arguable.

I still don't understand why. Why? Setting up the Windows PYTHONPATH on your own and then messing around in the clunky Windows command line utility is not an enjoyable experience for anyone (it is nothing like a Linux terminal)

Thermopyle
Jul 1, 2003

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

QuarkJets posted:

I still don't understand why. Why? Setting up the Windows PYTHONPATH on your own and then messing around in the clunky Windows command line utility is not an enjoyable experience for anyone (it is nothing like a Linux terminal)

Because it keeps you from understanding, and it's not hard unless not only are you new to programming but new to computers. Additionally, all the tutorials and help you find out there are going to know jack squat about your IDE.

Dren
Jan 5, 2001

Pillbug

Dominoes posted:

I've been storing historical stock data in a 130mb and growing json file, which I import/export from a python dict, which stays in memory while my program's running. Info is stored in the format {symbols: {dates: {attributes: values}}} . Loading the file is slow, and saving it is slower.

Would I benefit from a different storage method? Does SQLite sound appropriate for this?

The names of the attributes directly affect file size and performance. I've taken to using a shorthand, like replacing 'close price' with 'c'. This seems to indicate that JSON may not be an appropriate format.

I don't mean to discourage you from SQLite because it is completely appropriate for this task but since you already have your data stored as json transitioning to mongodb would likely be very easy (mongodb stores data in json format). Using a relational database would mean that you have to learn something about how to design tables for a relational db. Again, that's not bad, in fact it's a really good thing to learn, but mongodb would be easier.

QuarkJets
Sep 8, 2008

Thermopyle posted:

Because it keeps you from understanding, and it's not hard unless not only are you new to programming but new to computers. Additionally, all the tutorials and help you find out there are going to know jack squat about your IDE.

Keeps you from understanding what?

jony neuemonic
Nov 13, 2009

QuarkJets posted:

Keeps you from understanding what?

How to janitor your Windows computer, a vital skill for any Python programmer.

Dren
Jan 5, 2001

Pillbug
If someone is going to learn python on windows they probably should know about the command line. Some kind of IDE is not a bad idea too since editing with notepad is garbage. Whether or not someone uses an IDE to run their programs is up to them. Some people like it, some people don't.

Thermopyle
Jul 1, 2003

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

QuarkJets posted:

Keeps you from understanding what?

Python.

Learning programming concepts, Python syntax and whatnot, and all the concepts inherent in modern Python IDE's is too much to introduce.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Dominoes posted:

I've been storing historical stock data in a 130mb and growing json file, which I import/export from a python dict, which stays in memory while my program's running. Info is stored in the format {symbols: {dates: {attributes: values}}} . Loading the file is slow, and saving it is slower.

Would I benefit from a different storage method? Does SQLite sound appropriate for this?

The names of the attributes directly affect file size and performance. I've taken to using a shorthand, like replacing 'close price' with 'c'. This seems to indicate that JSON may not be an appropriate format.
SQLite is an option, but depending on the kind of work you're doing, you might consider using something like HDF5, which also integrates really nicely with pandas dataframes. It works really well for pseudo-sequential data like the time series stuff you're dealing with.

QuarkJets
Sep 8, 2008

^^^ Agreed, HDF5 is a pretty rad format.

Thermopyle posted:

Python.

Learning programming concepts, Python syntax and whatnot, and all the concepts inherent in modern Python IDE's is too much to introduce.

Having to set up your Windows python environment by hand and then running things from the command line is going to require introducing a lot more non-Python concepts than using a simple IDE like Spyder, which is basically a text editor and a Python terminal with the OS environment properly set up for you. No additional concepts need to be taught. You're getting hung up on the additional features of an IDE, but those are all optional. A new user doesn't need to be introduced to any IDE concepts, and many of the Python IDEs are incredibly intuitive and let you start learning Python immediately. The roadblocks that you're imagining are... imagined

Basically what I'm saying is that the Notepad and Windows cmd route takes all of the fun out of Python programming and requires a new user to go through a lot of unnecessary bullshit, whereas a basic IDE lets you get started and learning Python right away. Even the distributors of Python recognize that, which is why the Python.org distribution comes with an IDE

onionradish
Jul 6, 2006

That's spicy.
I use both the Windows console and PyCharm, but when I started learning I was using just Notepad++ and the console. (I later moved up to Spyder before switching to PyCharm.)

One of the early and recurring negative experiences I had with the Windows console is its inability to display any Unicode or Windows characters. I spent far too much time trying to understand what was wrong with some piece of code only to discover that there was nothing wrong with the code at all. The problem was "print"-ing to a crappy console. An IDE (even IDLE) can at least run
code:
print u'\u2019'
without failing.

A full IDE like PyCharm can be overwhelming for sure, but it can be used as just an editor and output console without learning much about the rest of the IDE -- there's still plenty of stuff in it I've never used at all. While learning, I appreciated its auto-inspection to catch stupid typos and its "nagging" about missing docstrings, line length, etc. to remind me about good coding habits. When I ignore the guidelines, it's a conscious choice. It's also much easier to set breakpoints, step through and watch variables in a GUI for code as it starts to get more complex than it is at the console level.

Adbot
ADBOT LOVES YOU

Nippashish
Nov 2, 2005

Let me see you dance!

QuarkJets posted:

Basically what I'm saying is that the Notepad and Windows cmd route takes all of the fun out of Python programming and requires a new user to go through a lot of unnecessary bullshit, whereas a basic IDE lets you get started and learning Python right away. Even the distributors of Python recognize that, which is why the Python.org distribution comes with an IDE

This. Insisting new users start with the command line and vanilla packages is like insisting that people learn assembly before a higher level programming language.

  • Locked thread