|
onionradish posted:It is; I'd avoid him on principle based on how he lashed out against critics, aside from suspecting anything he says as being out of date since he's been so anti-Python3. Suddenly, he'd be worth listening to? Eela6 posted:BTW, should we make a new Python thread? This one is pretty crusty. It might be nice to have an updated OP with some of this material.
|
# ? Feb 27, 2017 19:43 |
|
|
# ? Jun 1, 2024 05:19 |
Dominoes posted:Thx! Sent him the ATBS link; seems perfect. I'm recommending Anaconda since it has all the packages. I can only type with one hand because of health issues, so it will take a little longer than that. But I'm happy to do it.
|
|
# ? Feb 27, 2017 20:37 |
|
Some highlights you could put in: -Tutorials and instructional books -Strengths and weaknesses (ie easy, versatile, sucks at distributable standalone progs and inappropriate for sys programming) -Installation guides (eg Anaconda vs pip wheels / linux packages / Chris Gohlke's installers) -IDEs -Scipy-stack info -Popular packages (requests, pytz, sqlalchemy, beautifulsoup, toolz etc) -GUI (Qt5, Kivy, TKinter etc) -Web dev section, with a link to the Django thread -Resources (like onion's reddit recommendations) -Alternatives (ie R for stats, Julia for numerical things, Ruby for web dev) -Neat projects (micropython, numba, pypy etc) -Good articles and notebooks (Kalman filters, Data Science Handbook) Dominoes fucked around with this message at 20:55 on Feb 27, 2017 |
# ? Feb 27, 2017 20:45 |
Dominoes posted:Some highlights you could put in: I agree w/ the inclusions of all of these segments. However, I have zero front-end or webdev experience. I don't feel qualified to talk about : -Popular packages (requests, pytz, sqlalchemy, beautifulsoup, toolz etc) -GUI (Qt5, Kivy, TKinter etc) -Web dev section, with a link to the Django thread Also, I use Anaconda through windows powershell. I can't talk about the linux toolchain. If someone else in the thread could produce these sections that would be cool
|
|
# ? Feb 27, 2017 21:26 |
|
Probably late to the party but another rec for ATBS. I recently picked up Python without any programming experience besides a Java course over a decade ago. It was good to follow and felt good doing something practical. I did a coursera course afterwards and it felt like a walk in the park due to already have done ATBS.
|
# ? Feb 27, 2017 22:00 |
|
I've got a new thread for Python pretty much ready to go from a couple years ago, I just never got around to posting it. I'll clean it up and post it by the end of the week. edit: Well, I just read it over and its kind of dated and actually from the end of 2013. If someone wants to start with it as a base here it is. There's good suggestions in the comments on that page for improvements. Thermopyle fucked around with this message at 22:16 on Feb 27, 2017 |
# ? Feb 27, 2017 22:11 |
|
Dominoes posted:Hey dudes. What are the best ways to learn Python, for someone with no experience? I learned from Codeacademy, which was OK. The OP looks out of date. If you have access to O'Reilly books, I would start with 'Learning Python' and then 'Python Cookbook'. You learn 'this is Python' and then they show you 'this is how to do stuff with it'
|
# ? Feb 27, 2017 22:41 |
|
onionradish posted:
This has been an amazing book to learn from and I still go back to it every other project or so.
|
# ? Feb 28, 2017 00:49 |
|
https://pymotw.com/3/ deserves a mention. I know the standard modules are a functionality mausoleum but there's still good stuff in there i you know where to look.
|
# ? Feb 28, 2017 16:43 |
|
I've got a Python function that I've added throughout a script I want to run autonomously. Its purpose is to print various log information to a txt file. What would the bests way to log any errors that might occur to the same file? code:
|
# ? Mar 1, 2017 17:26 |
|
Look into the logging module, it has a decent tutorial. If you want to write messages to the console and a file at the same time, you'll want a logger with a FileHandler and a StreamHandler attached. E: I'm on a phone so can't type code, here's the basic tutorial https://docs.python.org/3/howto/logging.html a witch fucked around with this message at 17:43 on Mar 1, 2017 |
# ? Mar 1, 2017 17:38 |
|
a witch posted:Look into the logging module, it has a decent tutorial. Awesome thanks. Another question - I have a script running that uploads files to dropbox. If the internet goes down mid upload, I get a MaxRetryError. Trying the following doesn't work though code:
|
# ? Mar 1, 2017 20:21 |
What do you want to happen?
|
|
# ? Mar 1, 2017 20:24 |
|
Eela6 posted:What do you want to happen? I want the function to return false. However, with that code I'm getting "NameError: global name 'MaxRetryError' is not defined".
|
# ? Mar 1, 2017 20:25 |
|
huhu posted:I want the function to return false. However, with that code I'm getting "NameError: global name 'MaxRetryError' is not defined". Is MaxRetryError the type of the exception being thrown? You will have to import it to make the name visible.
|
# ? Mar 1, 2017 20:32 |
This is what you have:Python code:
Python code:
Python code:
You need to make one of these two changes to let it know where the error lives so you can catch it. Python code:
Python code:
Eela6 fucked around with this message at 21:16 on Mar 1, 2017 |
|
# ? Mar 1, 2017 20:57 |
As a brief note, huhu, you might want to look in to how to phrase technical questions better. This section on stackoverflow might help you. You've asked questions a couple of times that were phrased in ways that made it difficult for us to help you, because we've had to guess at what your 'real question' is. Eela6 fucked around with this message at 21:09 on Mar 1, 2017 |
|
# ? Mar 1, 2017 21:05 |
|
poo poo wrong thread n/m
|
# ? Mar 1, 2017 21:36 |
|
As much as i'd like to retire this thread, well, it's almost a decade now, but it's been a long decade.king_kilr posted:I got started with Python a few months a go, I've been using it for exclusively web stuff so far, using Django. I really like it so far, I would say the best part is code is so readable.
|
# ? Mar 2, 2017 04:42 |
Well, why don't we make a new thread now, and we'll continue to support the old one while people migrate over? I'm sure almost everyone will switch over by the end of the year! We can call it PyThread 3.
|
|
# ? Mar 2, 2017 05:21 |
|
Do I use 3 or 4 spaces in my docstrings if I'm using sphinx? e: logging chat: If I use a third party package to build an app, and that third party package has a logger already set up, should I just hook into their logger or should I need to create my own and keep them separated? The info that their logger outputs is useful to me; my extra log messages are just additional things I've added for my app. Boris Galerkin fucked around with this message at 16:01 on Mar 4, 2017 |
# ? Mar 4, 2017 11:21 |
|
Boris Galerkin posted:Do I use 3 or 4 spaces in my docstrings if I'm using sphinx? Create your own logger and logging config.
|
# ? Mar 4, 2017 17:25 |
|
huhu posted:
code:
(Is it in general preferred to use print to print to files in those contexts where it works?)
|
# ? Mar 4, 2017 17:44 |
I personally use the print function for almost all text output, even if I'm writing to standard error. However, using file.write is totally fine - they're both clear to the reader. Context managers are awesome.
|
|
# ? Mar 4, 2017 19:26 |
|
Anyone got any recommendations for a method of creating animations (avi/mpeg/mp4) from a bunch of .png files? I've inherited a collection of code that does this with cv2 (I think) but its awfully put together and throws lots of errors with the l/w/h parameters.
|
# ? Mar 5, 2017 00:30 |
|
Any reason you can't use ffmpeg or avconv?
|
# ? Mar 5, 2017 00:34 |
|
Zero Gravitas posted:Anyone got any recommendations for a method of creating animations (avi/mpeg/mp4) from a bunch of .png files? I've inherited a collection of code that does this with cv2 (I think) but its awfully put together and throws lots of errors with the l/w/h parameters. Virtualdub is pretty awesome. Just select fps, compression method, and any other settings and you get a nice video.
|
# ? Mar 5, 2017 01:14 |
|
Nippashish posted:Any reason you can't use ffmpeg or avconv? Yeah ffmpeg should do a flawless job and is made for doing this sort of thing. Invoke it with Popen if you want. I don't know what your inherited cv2 implementation looks like, Zero Gravitas, but opencv uses ffmpeg libraries for creating movies and the cv2 movie-writing API is pretty straightforward. It shouldn't be more than 20ish lines. Maybe just rewrite it the correct way? Is there something funky about your inputs, like they sometimes come in with different sizes or something?
|
# ? Mar 5, 2017 05:37 |
|
Thermopyle posted:Create your own logger and logging config. Okay thanks, will do. Another question: I've been trying out pytest and it's really neat. My test codes look much cleaner than with unittest, but what I like the most is the colored red/green output. I do something like TDD so I'm constantly alt-tabbing or tmux pane switching etc to another terminal to re-run tests. Is there already an established way to tell pytest something like "monitor test folder x and re-run your tests every single time source code in folder y changes"? And going further (but maybe too Vim specific) is there a way to have pytest color my vim status bar red/green depending on status so I don't even have to look over to the other terminal unless I need to read the status messages? e: what would be even better is if it would add information to my vim status line, just something short like: "b3,r66; b8,r23", telling me that one test failed in buffer 3 on line 66 so I could just switch my vim buffer directly to "3" and then see which test failed. Boris Galerkin fucked around with this message at 15:34 on Mar 5, 2017 |
# ? Mar 5, 2017 15:31 |
|
Boris Galerkin posted:I've been trying out pytest and it's really neat. My test codes look much cleaner than with unittest, but what I like the most is the colored red/green output. I do something like TDD so I'm constantly alt-tabbing or tmux pane switching etc to another terminal to re-run tests. Is there already an established way to tell pytest something like "monitor test folder x and re-run your tests every single time source code in folder y changes"? pytest-xdist gives you a watch option(-f). quote:And going further (but maybe too Vim specific) is there a way to have pytest color my vim status bar red/green depending on status so I don't even have to look over to the other terminal unless I need to read the status messages? i haven't used vim for actual dev in a while, but are you using some plugin like python-mode or just rolling your own config? maybe do something like run pytest on save and check for v:shell_error instead of watching? personally i just use pycharm and toggle auto-test on though
|
# ? Mar 5, 2017 16:42 |
|
Eela6 posted:I can only type with one hand because of health issues, so it will take a little longer than that. But I'm happy to do it. Thermopyle posted:I've got a new thread for Python pretty much ready to go from a couple years ago, I just never got around to posting it. I'm going to do it if y'all don't.
|
# ? Mar 5, 2017 17:51 |
Dominoes posted:I'm going to do it if y'all don't. Please do! It is painful for me to type more than a little at a time, so I am happy to pass the buck. Eela6 fucked around with this message at 21:03 on Mar 5, 2017 |
|
# ? Mar 5, 2017 20:45 |
|
Dominoes posted:I'm going to do it if y'all don't. Don't forget that google doc i posted. If you want to use it, it should mostly be copy/paste with some updates for modern python.
|
# ? Mar 5, 2017 22:39 |
|
Ha! Just clicked this as I'm drafting one; we have the same idea about the opener! Merging them now.
Dominoes fucked around with this message at 23:27 on Mar 5, 2017 |
# ? Mar 5, 2017 23:23 |
|
Draft. CAO March 2017 Python code:
Python’s a high-level language featuring code that’s easy to learn, read, and write. It’s popular, has a robust collection of third-party modules, and a large community willing to help. It’s friendly to multiple programming styles; procedural and functional; object-oriented, or not. Generally, it runs slowly compared to other languages; eg C, Java, Julia, Rust, and Haskell. Python is versatile, and is especially popular for scientific computing and web development. It’s not suitable for systems programming, and is weak when dealing with distributable stand-alone programs. What makes Python different from other languages? -Significant whitespace. In other words, you don’t use braces to indicate blocks of code, you use indentation. -Duck typing. If it walks like a duck…. What this means is that Python doesn’t care about the actual type of the objects you’re working with as long as the object implements the correct attributes and methods. Note that Python is also strongly typed, meaning that you can’t can add a string, a number, and a file object together to get some guessed-at result. -Batteries included. Python comes with an extensive standard library. General links Official docs Style guide Official third-party package repository Pyhon subreddit, Subreddit for beginners Learn Automate the Boring Stuff Dive into small projects Codeacademy provides interactive exercises. MIT OpenCourseware Think Python Installing Python and third-party packages There are two main paths for installing Python. If you’re new, download Anaconda; it has many common third-party packages built-in. You can install additional packages later, with its conda package manager, or using the official one, pip. Enthought Canopy is similar to Anaconda. You can also install Python directly from the Official downloads page.The default links on this page are for x86-versions; browse to the OS-specific pages to find the 64-bit downloads. If you’re on Linux, you probably have Python installed already – perhaps multiple versions… be careful! Third-party packages can be installed with the built-in package manager pip. Just run pip install packagename. Or create a text file of package names, and install with pip install -r requirements.txt. Packages that include code from other languages like C may work this way, or you may have to install using your system package manager (ie in Linux), or installers from This page on Windows. Anaconda users can install most packages with conda install packagename. Selected third-party packages
Virtual environments Check out virtualenv and related tools. Virtualenv is a tool to create isolated Python environments. The introduction explains what it is and why you want want it. Many people use virtualenvwrapper to make working with virtualenvs easier.Virtualenv-burrito makes setting up the two easy. Anaconda has its own virtual-environment tools. Scientific computing The Scipy Stack is a collection of modules that expand python’s numerical-computing capability. They work well together, but learning when to use each package can be tricky. The Python Data Science Handbook, linked below, can help. All of these packages can be installed with conda; most with Pip. Numpy: Provides a multi-dimensional array data type that allows fast vectorized options. Great for linear algebra, and nearly all numerical computing in Python relies on it. Scipy – A collection of unrelated tools, divided into submodules. Includes modules for statistics, Fourier transforms, scientific constants, linear algebra, signal processing, image manipulation, root-finding, ODE-solvers, and specialized functions (Bessel etc) etc If you're considering implementing a common scientific operation by hand, check Scipy first.Documentation here Matplotlib– Plotting. Robust and flexible. Has two APIs, both of which are awkward. Sympy – symbolic computation. Manipulate equations abstractly, take derivatives and integrals analytically, manipulate variables. Pandas – Used in statistics and data analysis; wraps Numpy arrays with labels and useful methods. Ipython / Jupyter. Exists as three related components: Ipython terminal: A powerful improvement over the default. Ipython QtConsole: Similar to the terminal app, but has advantages provided by a GUI. Notebook: Work on pages of mixed code, LaTeX, and text on redistributable web pages. Set to be replaced by a new project called Jupyter Lab Related: Scikit-learn is a machine-learning package with a simple API. Solves classification, regression, and clustering problems with a range of techniques. Tensorflow and Theano provide neural net frameworks. IDEs PyCharm Robust and full-featured. Its community edition is free, and works well for Python. Its Profession edition costs ~$60/year, and includes addition features like web-development tools. Free for students and contributors to open-source projects. Spyder is targeted at scientific computing, and is simpler than PyCharm. Can be installed with pip, and is included with Anaconda. If you'd prefer a text-editor with language-specific features, try Visual Studio Code or Atom We development Python is great for server-side web development, when paired with one of these packages: Django – Batteries-included and popular. Intimidating to start with, and involves many files working together, but includes most of what you need to build a website. Extensive docs, and many people who can help on StackOverflow. Flask Minimalist, and easy to start with. Customizable. As your projects grow, you’ll likely want to add other modules for things like database management, migrations, admin, and authentication. Pyramid and Pylons are other popular frameworks.This page shows an overview of what's available. Warning: Diving into these packages directly can be challenging if you’re new to web development, since it requires proficiency in several skills. I recommend learning Python, database basics, HTML, CSS, and Javascript independently first. Heroku is a service that makes hosting Python websites easy; it has free plans for development, and can quickly scale up for production use. Alternatives For scientific computing: Julia is fast, and has more natural syntax for math and equations. Similar syntax to Python; it’s easy to pick up one if you know the other. code:
Python code:
Statistics and data analysis: R. Specialized, popular language with a large collection of stats packages. Web development: Ruby on Rails is another high-level framework with nice syntax. Complementary languages C: Python runs on C, so it's a natural language to write high-speed extensions in. HTML, CSS, Javascript, and JQuery for web development. SQL, if you use Python to manage databases. Expanding Python into new realms PyPy is a Just-in-time (JIT) compiler for Python that allows a subset of the language to run very fast. Numba is another way to speed up Python to near-C-speeds with a JIT. By applying a decorator, can make python functions run much faster; but limits which parts of the language you can use in these functions. Usually requires writing out loops manually, where otherwise you might used vectorized code. Micropython allows you to code custom microcontrollers with Python. Neat specialized tutorials Python Data Science Handbook – Introduction to scientific programming in Python. Kalman and Bayesian Filters in Python – A detailed introduction to Kalman filters, making heavy use of Python. This OP’s a community effort; post in the OP or PM-me for updates and edits. Dominoes fucked around with this message at 15:03 on Mar 6, 2017 |
# ? Mar 5, 2017 23:37 |
|
Put Neural Networks under Scientific Computing. You're using print in command mode in the 2nd example with print. Your quotes are not ASCII, so I can't copy-paste your code examples List comprehensions are the best thing ever so why not feature them in one of the examples? I also use Anaconda and I think most of us do, but shouldn't Canopy Enthought at least get a mention?
|
# ? Mar 6, 2017 00:14 |
|
Done. Sorry Therm - I'm really butchering your material!
Dominoes fucked around with this message at 00:38 on Mar 6, 2017 |
# ? Mar 6, 2017 00:26 |
It might be fun to have Python code:
Also a "why use Python" interpreted -> fast write, run, tweak loop readability ease of use scientific and numeric tools power of multiple programming paradigms, metaprogramming, operator overloading, and other dynamic Lang tricks __double_underscore_methods__ Why not: Interpreted, dynamic - whole class of errors that could he avoided with typechecking compilers Interpreter overhead / slow Portability issues / resolving dependencies, toolchain GIL/Concurrency/Parallelism issues Metaprogramming, operator overloading and other dynamic lang tricks dangerous Eela6 fucked around with this message at 00:59 on Mar 6, 2017 |
|
# ? Mar 6, 2017 00:47 |
|
The code examples probably aren't useful. People don't read megathred OPs to learn the language. They're also a really big thing to put before the main content. They'd be better in a second post if you must have them.
|
# ? Mar 6, 2017 01:44 |
|
|
# ? Jun 1, 2024 05:19 |
|
I agree Nip; going to cut them entirely.
|
# ? Mar 6, 2017 01:58 |