|
What I normally do is type out my longass string and then find spots in it that make sense to break it up. Then I put the cursor there and press enter and PyCharm moves it all to the next line while taking care of quotes. Also, for whatever reason I find myself using long strings as function params (logging usually) more often which doesn't require the extra set of parentheses which is nice.
|
# ¿ Mar 6, 2017 17:24 |
|
|
# ¿ Apr 29, 2024 09:05 |
|
QuarkJets posted:So anaconda comes with an assload of its own libraries and binaries, and sometimes this causes problems for me. For instance, I can't just set my PATH to the anaconda/bin folder because then I'm overriding the default path for various tools in a build environment where the versioning is actually pretty important. I'm having difficulty picturing your exact problem, but the general idea is why I always use miniconda...have you looked at using that?
|
# ¿ Mar 6, 2017 23:13 |
|
huhu posted:I'm reading about RESTful web services as they relate to Flask. In the introduction, It talks about how you might need to have multiple versions of your website because not everyone can access the new version immediately (i.e. a smartphone app won't be up to the newest version until the user downloads the new version). The smartphone app was the only example given and I'm struggling to understand what else would justify having separate versions of a website with Flask? If you're providing an API for consumption by third parties you need a versioning and deprecation policy. If you're providing an API for consumption only by yourself, you should probably version it because it's easy to do and will help you in the future if your project grows or you open it up to others or whatever. Any decent REST API will make versioning a simple matter of setting a config variable to True. It seems a little odd to word it as having different versions of a website...I've never heard of that. Only different versions of the API. Though, with modern web development, your website is often just another consumer of your API.
|
# ¿ Mar 8, 2017 20:37 |
|
I switched to PyCharm EAP (basically jetbrains beta program) today just for the hell of it. The first thing I've noticed is this goddamn amazing "zero latency typing" thing. I've had zero issues with typing latency in PyCharm, but its amazing how great it feels now.
|
# ¿ Mar 8, 2017 23:08 |
|
IAmKale posted:That's Python type annotations, available since 3.5. It doesn't activate strong typing or anything, it's just a way to add in expected inputs and outputs to method definitions. The part after -> is the method's return value type. And by "expected" he means expected by Python tools. For example IDE's can use it as hints to highlight when you're trying to pass an int to a function expecting a tuple or whatever. Also, you can use MyPy to do static typing on your code.
|
# ¿ Mar 9, 2017 16:55 |
|
dougdrums posted:- Is there an advantage to annotating my function definitions beyond having some documentation? Thermopyle posted:And by "expected" he means expected by Python tools. For example IDE's can use it as hints to highlight when you're trying to pass an int to a function expecting a tuple or whatever. Also, you can use MyPy to do static typing on your code. For example, PyCharm uses type annotations to save you from yourself.
|
# ¿ Mar 9, 2017 19:37 |
|
The one thing I don't like about more advanced typing annotations is that they can make the signature too long and noisy and those are the signatures they're most useful with. Syntax highlighting and other IDE features help with that, though.Python code:
|
# ¿ Mar 9, 2017 22:38 |
|
Tigren posted:I know you know better, but one might suggest you could either get rid of the type hints or clean up that signature with a better function name. Yes, it was just an example of what can happen.
|
# ¿ Mar 9, 2017 23:13 |
|
dougdrums posted:I've just been doing like: Yeah, that's basically what I do
|
# ¿ Mar 10, 2017 00:51 |
|
Boris Galerkin posted:Because it was just an example. I agree that property accesses are more "pleasant" to type and look at than function calls. Anyway, do you ever split your code into different files for reasons other than language-mandated reasons? The general reason you'd do that is one of the general reasons you'd use objects. Of course, OOP is full of stupid ideas as well. It's a good idea to become familiar with different paradigms like OOP, functional, etc so you don't end up just using what you know and missing out on better ways to solve problems. You talking about your background makes me think you might like learning Elm, as it's completely different from what you'res used to for completely different purposes, and it'll really expand your mind about what you can do with Python as you can implement a lot of the same functional ideas in Python.
|
# ¿ Mar 11, 2017 17:36 |
|
Boris Galerkin posted:Yep of course. I split my code/functions into separate files/modules in a way that makes sense (e.g., functions that act on tensors go in tensors.py). I'm just having a hard time seeing the practical difference between these two though: You'll often see classes used in python to lump logically-related code together, so in just that sense you can see them as another unit of subdivision. You have packages (directories with a __init__.py) file, modules (.py files), and classes, all that help you organize code. That being said, classes are more than just a way to group logically-related code together. It's hard to describe a slam-dunk case for objects because everything you can do with objects you can do with functions. Objects are for helping you reason about your code, they don't make your code able to do new things. I think the best you can do is understand how objects work and be aware of them. Try to use them even when you don't think you need them. It'll help you get a feel for them so that when you do encounter problems that would benefit from an OOP approach, you'll know to use them. There's a not-entirely-unjustified school of thought in python-land that too many developers pull out classes unnecessarily.
|
# ¿ Mar 12, 2017 18:23 |
|
I always use the one I stole from django.Python code:
|
# ¿ Mar 17, 2017 00:01 |
|
Boris Galerkin posted:e: vvv What's the proper way to do it then? Maybe just a regular function or a classmethod on Beer. Python code:
|
# ¿ Mar 18, 2017 16:19 |
|
The Gunslinger posted:Haha holy poo poo I hope it's that simple, just got into work but I'll RDP into my machine later and check. Thanks man. This is probably it. I've been writing python for a decade and this will still occasionally trip me up...particularly when it's a large project and I've been doing lots of refactoring.
|
# ¿ Mar 21, 2017 15:19 |
|
a witch posted:What's the current hotness for type annotations and checking? Mypy or something else? mypy
|
# ¿ Mar 28, 2017 19:15 |
|
vikingstrike posted:Does mypy have support for pandas objects? So I could set the return/input type to be pd.Series or pd.DataFrame? https://github.com/pandas-dev/pandas/issues/14468
|
# ¿ Mar 28, 2017 21:51 |
|
Baby Babbeh posted:Thanks for inadvertently bringing f-strings to my attention. I always use str.format() but that seems like a better way to do that... They're the best. It's weird that .format() has always bothered me as much as it has, but dang it sucks.
|
# ¿ Mar 29, 2017 20:16 |
|
The Django thread barely gets enough traffic to justify its existence. You may be better off just talking Flask in here?
|
# ¿ Mar 30, 2017 15:34 |
|
funny Star Wars parody posted:Ok here's a dumb question: I want to make a unicornhat (which uses a Python library) on a raspberry pi do something when a new order is placed, and according to the Shopify API, you would use their webhook to do it and you supply them with the URL for the webhook to deliver a HTTP POST payload to in json format. Yeah, you need a server running. Basically shopify will call an url on a server you control when orders are placed. Then your code does something when that happens. It will work fine on a raspberry pi. Flask and Django both are both capable of doing this is like 20 lines of code or something. The hardest part will be learning how to do it because for some reason understanding how the web works is not easy despite it being pretty simple.
|
# ¿ Mar 31, 2017 16:30 |
|
Tigren posted:This is the perfect use case for Flask. You don't need the bells and whistles of Django. FWIW, it's about the same in Django. Flask is fine and there's a 50/50 chance I'd use it for the project myself, but occasionally I like to point out that people have this idea that Django is really complicated or something. It includes a lot more "in the box" than Flask, but it'd work basically just like Flask in this case. Single file, basically same # lines of code, etc.
|
# ¿ Mar 31, 2017 18:25 |
|
Thanks for reminding me about Zappa. I keep meaning to try it out on my next project and then forget. edit: oh yeah now I remember why I really haven't tried it. No Python 3 support.
|
# ¿ Apr 1, 2017 00:40 |
|
Foxfire_ posted:Huh, I was expecting the pandas overhead to be much smaller. Some testing shows that it goes: Have you tried with Cython? (no clue if it works with pandas or numpy)
|
# ¿ Apr 1, 2017 14:08 |
|
oliveoil posted:The Python documentation says "Long integers are now stored internally either in base 2**15 or in base 2**30": https://docs.python.org/2.7/whatsnew/2.7.html#optimizations The general programming thread is a better place to ask this probably.
|
# ¿ Apr 7, 2017 14:47 |
|
Temperature and humidity tracking automatically makes me think of a time series database. I haven't used it but I've heard of opentsdb. Or even good old RRDTool. You could probably set up your own service for either of those on a 5/month DigitalOcean server. But then again, maybe a time series database isn't what you want, it's hard to say without knowing what you'll do with the data. No matter what you do I bet the DigitalOcean server idea would serve you well if you're really wanting a cloud/remote thingy. InfluxDB is another good option, I'm pretty sure there's hosted versions of that out there if you didn't want to set up your own server. Then you could do sweet visualizations with Grafana.
|
# ¿ Apr 11, 2017 06:03 |
|
huhu posted:I started developing with Sublime Text and then switched to PyCharm since I've been working mostly with Python. However, my new job has me focusing on Flask apps and PyCharm seems to be a bit lacking when it comes to dealing with HTML, CSS, and JS. I miss all the awesome plugins that come with Sublime Text as well. Am I missing something or should I be looking at something else to be developing Flask stuff? What? PyCharm is amazing for HTML/CSS/JS. It's basically a superset of Webstorm which is already widely liked for webdev stuff. I often use PyCharm for projects that are only HTML/CSS/JS. Maybe ask about some specific things you're missing and I bet you'll find that most of them are supported.
|
# ¿ Apr 12, 2017 22:20 |
|
QuarkJets posted:I'm not sure that it has ever mattered to me; I just kind of assumed that the last value of the comprehension variable would be available in the local scope and didn't realize that this was actually undesired behavior. This is exactly right. It was just the way it was. It was never a problem.
|
# ¿ Apr 12, 2017 23:23 |
|
Right, I got that from your first post. I'm asking like what?
|
# ¿ Apr 13, 2017 18:17 |
|
funny Star Wars parody posted:Jetbrains makes a lot of really nice stuff and I really like IntelliJ for Java and JavaScript. I found Pycharm to be frustrating to use because most small Python apps aren't organized the way Pycharm seems to try to organize them What does this mean exactly? AFAIK, PyCharm doesn't care how your projects are organized. I often go through a lot of different structures on a project. It starts out small with a few files just right next to each other, them I move stuff into packages then I move stuff into a full-blown thjngamajig with a setup.py, etc... PyCharm doesn't seem to give a crap and in fact helps with that since it does a fine job with automatic refactoring.
|
# ¿ Apr 15, 2017 23:03 |
|
IMO, typing.NamedTuple is also better than collections.namedtuple with no extra dependency. I haven't used attrs, though.
|
# ¿ Apr 16, 2017 23:27 |
|
I think the continued existence of whatever packaging system or repository is a hard problem. Continuum is just one company. PyPI (where your packages come from when you pip install something) is basically developed by one guy. Last I heard, it's infrastructure would cost 40 grand/month if Rackspace wasn't donating it.
|
# ¿ Apr 18, 2017 16:30 |
|
Epsilon Plus posted:As a relative newbie, if dependency injection is less popular in Python than it is in other languages, how do you handle cases in Python that you'd typically use dependency injection for in, say, Java? DI isn't exactly uncommon in Python. It's just that because of Python's dynamic nature you don't really need a lot of scaffolding that you need in other languages so it often doesn't go by the Official Pattern Name Dependency Injection. You just write stuff in Python in a pythonic way and then later someone is talking about Python and DI and you go "you know I guess I just did use DI!" edit: Forgot to add that super() is an effective and easy way of doing DI in python. Thermopyle fucked around with this message at 21:51 on Apr 20, 2017 |
# ¿ Apr 20, 2017 20:41 |
|
KernelSlanders posted:I don't know what your specific application is but nine times out of ten when someone is asking for a GUI toolkit the right answer for their use case is HTTP. I assume you mean HTML. And I agree with you.
|
# ¿ Apr 22, 2017 17:51 |
|
ButtWolf posted:Hey, hopefully easy question for ya'll: I wrote a webscrapey thing last year w BeautifulSoup. I changed variable names to get the new data (new <tr> headings). Nothing works now. I'm out of practice and wasn't good to begin with. Can anyone help. BTW, it worked perfectly last year. You should give us the actual error stacktraces so we don't have to go through your code line by line to figure out whats what.
|
# ¿ May 10, 2017 16:04 |
|
This is a nice library that I use fairly often. backoff. When working with external APIs over the network you have to handle the stuff that happens when you're dealing with networks and other network devices. This library helps with that. Amazon has a good post on their architecture blog about the best algorithms for choosing a time to wait between retrying failed requests if you want to read about it. Anyway, it's pretty simple to use...you just decorate the function that might fail and the decorator retries the function until its successful. Simple example that backs off each request by an exponential amount of time: Python code:
Python code:
There's another, more popular, library called Retrying that you can take a look at as well. The reason I don't use it is that it doesn't support the recommended algorithm in that Amazon blog post, but you might be interested in looking at it as well.
|
# ¿ May 15, 2017 20:55 |
|
PyCon 2017 videos are up.
|
# ¿ May 21, 2017 23:31 |
|
Loezi posted:I'm doing something relatively simple and Bottle seems like it's fully adequate for my uses. Is there some reason for using Flask over it if I don't need authentication or anything like that? In practice, I only need to serve an API with three distinct endpoints, one of which takes query parameters. Bottle is fine.
|
# ¿ May 23, 2017 06:24 |
|
huhu posted:I would like to debug JavaScript inside a PyCharm for Flask projects. I see that I can set breakpoints in the JS code but PyCharm always skips over them. The only tutorial I can find online involves debugging static HTML and not Jinja2 templates. I haven't debugged JS in a jetbrains IDE in years, but I seem to recall it was easier if I used an external js file included in my templates via a script tag.
|
# ¿ May 30, 2017 16:16 |
|
huhu posted:stuff You'll probably get more help on StackOverflow. I will say this...the reason I haven't used the JetBrains JS debugger in years is that the chrome devtools debugger is superior in every way that I can think of. Depending on what you're doing you might be better off just using that.
|
# ¿ May 30, 2017 17:20 |
|
Rocko Bonaparte posted:Has anybody dabbled with dependency injection with Python? I have reason to implement something like an API for getting implementations of APIs, and DI sounds like the way to go. I especially think back to how Angular managed stuff like this. I've done some experiments in this direction, similar-ish to what Tom Christie talks about in that video MonkeyMaker just posted. I think it has a lot of potential. You'll find that a lot of DI/IoC stuff in Python is never called that because DI/IoC just comes naturally to python due to its dynamic nature with first class everything.
|
# ¿ Jun 2, 2017 16:28 |
|
|
# ¿ Apr 29, 2024 09:05 |
|
This isn't going to be too helpful, but that's not exactly a Python issue. Your computer can't find the ip for the hostname that's configured somewhere in that app.
|
# ¿ Jun 3, 2017 19:00 |