|
QuarkJets posted:That's technically correct, which is the best kind of correct. Kind of like how a bicycle is basically a Ferrari, your smart phone is basically a supercomputer, or how genital herpes is basically a cold sore Do you have any good resources for scientific computing with python you could recommend? I'm a scientific computing guy too and until a few months ago I've been working exclusively with Fortran and C. But now I've/we've switched to a new software package that's built on C++ but with python interfaces. I've managed to jump into python and get things running smoothly though the first few weeks were really confusing especially cause even though I "knew" what a class/oop was I didn't really know how to use them. Basically I've been reading a lot of "how to do things the python way" which are okay but I haven't found anything that was more on the lines of "how to do things the python way for fortran programmers with no oop experience."
|
# ? Dec 11, 2016 15:55 |
|
|
# ? May 9, 2024 03:50 |
|
Boris Galerkin posted:Do you have any good resources for scientific computing with python you could recommend? I'm a scientific computing guy too and until a few months ago I've been working exclusively with Fortran and C. But now I've/we've switched to a new software package that's built on C++ but with python interfaces. I've managed to jump into python and get things running smoothly though the first few weeks were really confusing especially cause even though I "knew" what a class/oop was I didn't really know how to use them. Basically I've been reading a lot of "how to do things the python way" which are okay but I haven't found anything that was more on the lines of "how to do things the python way for fortran programmers with no oop experience." Like many/most scientific computing people, I'm self-taught (because even graduate-level scientific computing courses are mostly worthless), so I don't really know of any good resources are for learning OOP with scientific programming. But I'm pretty sure they exist! I'd recommend asking in the scientific/maths computing thread For using Python you'll want to be aware of Numpy, which gives bindings to most of the good Fortran matrix math functions. It sounds like you're using a package that uses C++ for the lifting and Python as a glue language, which is really common and often very effective. Be aware that loops in Python are much slower than loops in C/Fortran, so the goal is to either write clever Numpy expressions or to export computationally-heavy loops to C/C++/Fortran (eg adding 1 to every element in an NxN array with Python for loops is slow, but the one-liner Numpy expression to do this is as fast as C/Fortran). The best advice is probably to write code in Python without caring much about efficiency, and then if speed is an issue start looking at how to make things faster; preemptive optimization is a trap and usually a waste of time. Since you come from Fortran/C, just think of a class as a special type of structure, in that it can hold both variables (attributes) and functions (methods). QuarkJets fucked around with this message at 22:01 on Dec 11, 2016 |
# ? Dec 11, 2016 21:55 |
|
I'm throwing together a simple CRUD webapp, for the first time in years. I took at look around at what was available, and settled on flask-appbuilder. Which leads to: * Opinions on flask-appbuilder? The task really is simple (like one straightforward db object, no relationships) and I want to get it done and cleared as soon as possible. * How do you handle flask-appbuilder migration / evolution of db schema? This seems to be weirdly missing from the documentation. Is it like any other flask app?
|
# ? Dec 14, 2016 12:08 |
|
outlier posted:I'm throwing together a simple CRUD webapp, for the first time in years. I took at look around at what was available, and settled on flask-appbuilder. Which leads to: Never used appbuilder, but the first google result for "flask-appbuilder migration" is this: https://github.com/dpgaspar/Flask-AppBuilder/issues/105
|
# ? Dec 14, 2016 16:24 |
|
I've been doing Python for about a year now, and I feel like I've finally gotten over the newbie hump. That is to say, given a task I can usually start to think about how I'd program it in Python, my Python programs mostly work, and when they don't it's not usually because of some giant, game-breaking flaw but rather because I made a small, dumb mistake that 5 minutes of Googling allows me to fix. That is to say, I'm out of the zone of easy gains and into the vast, featureless plateau of mid-game mediocrity. I know I'm not very good, I know I'm not really using the language to its fullest potential, but I don't know exactly what I should be doing next. And it's tough because most of the resources for learning are aimed at beginners. These are too easy, but anything more advanced I struggle to understand. So what are some good resources at this level? A lot of the stuff in the OP looks great, but it's also kind of old/often kind of 2.7 specific. Someone recommended O'Reilly's Python Cookbook as a good source for common Python patterns, but I'm also kind of the type of learner that needs a lot of the theory to pick things up. Memorizing a pattern doesn't really work for me, I need to know why if I'm going to remember to do it.
|
# ? Dec 15, 2016 21:23 |
|
I think I used to be in a similar situation to you, and what took me to the next level (going from "abysmal" to "rather embarrassing") was contributing code to an open source project full of good coders and high coding standards. I'd submit code, get devastating reviews, and learn. Github is a great learning tool.
|
# ? Dec 15, 2016 21:30 |
|
I'm at the same place. My personal next steps are understanding everything in the collections and abc libraries, and reading Fluent Python.
|
# ? Dec 15, 2016 22:29 |
Fluent Python is the best book on YouTube is a great resource for python knowledge, actually. Most of the presentations from the last four years or so of PyCons are available. Maybe start with Raymond Hettinger, who is a python core developer and one of the best python educators I've ever seen. 'Beyond Pep8' is a great piece on 'pythonic style', and his recent talk in Russia about async and parallelism was really good too, if you're looking for a place to start with that. If you don't have a formal CS background and like theory, you can't do better than the big white book Introduction to Algorithms . A real programmer should never spend too long without reviewing the core material. If you aren't familiar with these libraries, get familiar : collections, functools, itertools Eela6 fucked around with this message at 23:30 on Dec 15, 2016 |
|
# ? Dec 15, 2016 23:01 |
|
QuarkJets posted:Like many/most scientific computing people, I'm self-taught (because even graduate-level scientific computing courses are mostly worthless), so I don't really know of any good resources are for learning OOP with scientific programming. But I'm pretty sure they exist! I'd recommend asking in the scientific/maths computing thread Got any examples for this numpy stuff?
|
# ? Dec 17, 2016 15:38 |
|
Boris Galerkin posted:Got any examples for this numpy stuff? http://www.scipy-lectures.org/ https://ipgp.github.io/scientific_python_cheat_sheet/ http://kitchingroup.cheme.cmu.edu/pycse/
|
# ? Dec 17, 2016 17:22 |
Boris Galerkin posted:Got any examples for this numpy stuff? https://www.youtube.com/watch?v=EEUXKG97YRw
|
|
# ? Dec 17, 2016 17:29 |
|
One of my favorite things about javascript ES2015 is template literals.JavaScript code:
Python code:
Python 3.6 expected on the 23rd...
|
# ? Dec 18, 2016 00:42 |
|
I just noticed that on the Py3.6 release notes this week. I must say I haven't used str.format() much because of its verbosity for simple strings but I'm excited to try f-strings.
|
# ? Dec 18, 2016 05:05 |
|
I mean, it's nice, but at the same time, now Python has three string formatting options without any recommendations or standards for which ones you should use where.
|
# ? Dec 18, 2016 05:27 |
Suspicious Dish posted:I mean, it's nice, but at the same time, now Python has three string formatting options without any recommendations or standards for which ones you should use where. I fully intend to use f-strings exclusively going forward. I like the syntax a lot and I think they are easiest to understand. They work "pretty much how you would expect", which is generally a sign of good code. I don't think it's a ton of extra mental overhead for python programmers to understand. That said, I get that this is messier than it could be. It's not exactly living up to "there should be one way to do it". With the impending release of 3.6, I am most excited for the new dict/set {} implementation. Basically, all dicts are faster OrderedDicts. Since classes and functions use dictionaries internally, this opens up a lot of fun areas for metaprogramming! Eela6 fucked around with this message at 06:44 on Dec 18, 2016 |
|
# ? Dec 18, 2016 06:28 |
|
I think f-strings are really cool and I see nothing wrong with having a new, cool string formatting option that works well
|
# ? Dec 18, 2016 08:27 |
|
That seems cool but I wonder why it got adopted when .format() is perfectly acceptable, this could turn into unreadable nightmare code (to be fair, so could .format() if you don't name everything, but I'm imagining a world where people are just throwing lambdas and callables into their format strings because they're too clever for their own good), and its purpose seems to solely be to save keystrokes. Like, I don't think it's a bad idea, but it seems like an option that exists solely because it can exist, and given the existence of .format(), seems a bit excessive. Imagine someone doing this: Python code:
I mean, it's mostly theoretical for me because we're still on Python 2.7. I want Python 3, it's such a nice language Ghost of Reagan Past fucked around with this message at 17:37 on Dec 18, 2016 |
# ? Dec 18, 2016 17:24 |
|
The problem with .format() is that it removes the context of what a variable is from where it is in the string, especially when there are multiple variables to fill in. Consider the difference in readability between:Python code:
Python code:
Python code:
|
# ? Dec 18, 2016 17:45 |
|
Ghost of Reagan Past posted:You can do this terrible nonsense with .format() of course, but with .format() all that nonsense is contained at the end of the string and isolated from the string, so it's a bit more readable and easier to fix. A well-disciplined team would avoid this, but I've seen enough "clever" code in my day-to-day that I know someone would think this is a good idea and create an unmaintainable mess. I mean, people are going to write unreadable code no matter what tools you give them. Here's a couple of your choices: 1. Leave string formatting as it is and bad coders will make unreadable messes of their strings in the various ways .format() lets you do and good coders will have strings that look ok but have a lot of repetition. 2. Introduce f-strings and bad coders will make unreadable messes right in the middle of their strings and good coders will have strings that look great in a succinct manner. Personally, I prefer option #2.
|
# ? Dec 18, 2016 18:35 |
Thermopyle posted:I mean, people are going to write unreadable code no matter what tools you give them. Here's a couple of your choices: Python gives you a lot of power and freedom. It lets you do things the way you want to. The good side of this is that well-written Python is some of the cleanest and easiest to understand code out there. The bad side of this is that there is no floor on just how bad Python coding can get. There are plenty of languages that attempt to raise the floor by adopting a lot of restrictions, - Golang strikes me as an extreme example. Java doesn't have operator overloading for the same reason: abuses of operator overloading can make code almost impossible to understand. I think that's a valid approach for a language, but I like the way python is. It makes well-written libraries a pleasure to use. For example, let's take numpy. An expression like Python code:
[If you're reading the thread and not familiar with numpy or MATLAB, this means 'set every item in A that's less than 20 to zero'] Obviously a new way to format strings is not quite the same as operator overloading, but I think the same basic ideas apply. I've always enjoyed this aphorism and think it applies: "Python is a language for consenting adults." Eela6 fucked around with this message at 22:32 on Dec 18, 2016 |
|
# ? Dec 18, 2016 21:34 |
|
Ghost of Reagan Past posted:That seems cool but I wonder why it got adopted when .format() is perfectly acceptable, this could turn into unreadable nightmare code (to be fair, so could .format() if you don't name everything, but I'm imagining a world where people are just throwing lambdas and callables into their format strings because they're too clever for their own good), and its purpose seems to solely be to save keystrokes. Like, I don't think it's a bad idea, but it seems like an option that exists solely because it can exist, and given the existence of .format(), seems a bit excessive. This is like arguing that we shouldn't make screwdrivers because some idiot might poke himself in the eye.
|
# ? Dec 18, 2016 22:59 |
|
I have trouble with Mypy in Python 3.5, specifically with OrderedDict. I know that an OrderedDict is always going to have string keys and specific type as values, but when running the script it complains that I am trying to index a type. However Mypy is ok with it and even type checks the variables properly, warning if I try to insert bad type. Reduced example: Python code:
code:
|
# ? Dec 18, 2016 23:06 |
Just a guess, but the class constructor might be the wrong approach. I'm on my phone, but trycode:
This might be barking completely up the wrong tree, though.
|
|
# ? Dec 18, 2016 23:59 |
|
Xarn posted:I have trouble with Mypy in Python 3.5, specifically with OrderedDict.
|
# ? Dec 19, 2016 00:52 |
|
mystes posted:Can you even do this in MyPy? If OrderedDict is just a normal class, isn't there no way for MyPy to understand that it should actually take type parameters? Surely this is why you need the separate "typing" namespace? I'm don't know if there's a clean solution to this. You could probably call it a Dict and things would mostly work out. (although you're losing some of the self-documentation value; add a comment?). Or leave it as OrderedDict, but skip defining the key/val types. Here's a SA post with another thought: post
|
# ? Dec 19, 2016 04:15 |
|
mystes posted:Can you even do this in MyPy? If OrderedDict is just a normal class, isn't there no way for MyPy to understand that it should actually take type parameters? Surely this is why you need the separate "typing" namespace? Actually Mypy understands just fine Python code:
Dominoes posted:You could probably call it a Dict and things would mostly work out. (although you're losing some of the self-documentation value; add a comment?). Is some sort of OrderedDict standin not being in typing a bug or is it intended?
|
# ? Dec 19, 2016 09:34 |
|
Anyone have experience using Numba to run Python code on the GPU via CUDA? I have some working python code that is running on my GPU fine, but it is using 64-bit floating point operations. These are a lot slower than 32-bit operations on the GPU, but I can't figure out how to force Numba to use 32-bit. Is there a flag I can set somewhere that will force 32-bit operations to be used?
|
# ? Dec 19, 2016 16:44 |
|
Asymmetrikon posted:You can technically kind of replicate f-strings with format by doing: I wish there was room in the spec to add implicit naming to dictionary literals like JS is doing, you could just do something like Python code:
Huh, I thought 3 deprecated the modulo formatting, but I guess not? I mean, I would have, but whatever.
|
# ? Dec 19, 2016 17:13 |
|
Yes, the implicit dict keys from JS is another thing Python needs to implement, ASAP. It's a big quality of life improvement.
|
# ? Dec 19, 2016 19:30 |
|
They can't do what I did there because {thing} already means "make a set consisting of 'thing'". IDK how you get around that without doing something kind of gross and unintuitive.
|
# ? Dec 19, 2016 20:22 |
|
I may have mentioned it in this thread already, but PEP 519 is what makes me happiest about using 3.6 (and prompted me to install 3.6 on all of my machines shortly after beta 4 was released). I've been heavily using pathlib in my code since it was added to the standard library in 3.4, and it's always been kind of painful to wrap Path objects in str() when passing them to many standard library functions and convenience I/O functions in third party libraries. It's really nice to drop the calls to str() and not worry about what specific type I'm using, as long as it implements the os.PathLike protocol.
|
# ? Dec 19, 2016 20:52 |
|
Lysidas posted:I may have mentioned it in this thread already, but PEP 519 is what makes me happiest about using 3.6 (and prompted me to install 3.6 on all of my machines shortly after beta 4 was released). I've been heavily using pathlib in my code since it was added to the standard library in 3.4, and it's always been kind of painful to wrap Path objects in str() when passing them to many standard library functions and convenience I/O functions in third party libraries. It's really nice to drop the calls to str() and not worry about what specific type I'm using, as long as it implements the os.PathLike protocol. Pathlib is a godsend.
|
# ? Dec 19, 2016 20:55 |
|
Pathlib is hot garbage that assumes all file paths are unicode. It continues to perpetuate a flawed assumptions of how paths work. At least now the reason why it crashes if your home directory isn't encodable as unicode is that the pwd module is making the assumption rather than pathlib itself assuming that your home directory is encodable as a unicode string.
|
# ? Dec 19, 2016 21:36 |
|
qkkl posted:Anyone have experience using Numba to run Python code on the GPU via CUDA? I have some working python code that is running on my GPU fine, but it is using 64-bit floating point operations. These are a lot slower than 32-bit operations on the GPU, but I can't figure out how to force Numba to use 32-bit. Is there a flag I can set somewhere that will force 32-bit operations to be used? Have you tried importing float32 from numba and using that as the datatype for your data?
|
# ? Dec 19, 2016 22:06 |
|
Edison was a dick posted:Pathlib is hot garbage that assumes all file paths are unicode. It continues to perpetuate a flawed assumptions of how paths work. Maybe I'm a dummy but can you post a quick example of a home directory path that can't be represented by a unicode string?
|
# ? Dec 20, 2016 04:10 |
|
QuarkJets posted:Have you tried importing float32 from numba and using that as the datatype for your data? Yes, but you have to wrap every variable in the code with it. I know that the native CUDA API has an option that forces single-precision operations to be used, and was wondering if the Numba API exposed it somehow.
|
# ? Dec 20, 2016 06:00 |
|
yippee cahier posted:Maybe I'm a dummy but can you post a quick example of a home directory path that can't be represented by a unicode string? There were a bunch of posts by user hackbunny in the coding horrors thread (iirc) in the past week or two about the crazy encodings of path names. On phone, otherwise I'd find them for you...
|
# ? Dec 20, 2016 06:24 |
|
Thermopyle posted:There were a bunch of posts by user hackbunny in the coding horrors thread (iirc) in the past week or two about the crazy encodings of path names. http://forums.somethingawful.com/showthread.php?threadid=2803713&userid=0&perpage=40&pagenumber=954#post466866270
|
# ? Dec 20, 2016 06:44 |
|
What's the best all-around choice for an ORM? I am doing a simple project right now so it's not super critical but I'm trying to pick up skills that I could apply to other projects and I might as well start out properly. edit: is there anything with a feature like Hibernate's hbm2ddl.auto functionality where it can create a valid database from the mapping configs? Paul MaudDib fucked around with this message at 01:11 on Dec 21, 2016 |
# ? Dec 21, 2016 01:08 |
|
|
# ? May 9, 2024 03:50 |
|
Paul MaudDib posted:What's the best all-around choice for an ORM? I am doing a simple project right now so it's not super critical but I'm trying to pick up skills that I could apply to other projects and I might as well start out properly. SqlAlchemy if not using Django. Django's ORM if you are.
|
# ? Dec 21, 2016 01:29 |