|
Thermopyle posted: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. 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.
|
# ¿ Mar 9, 2017 22:40 |
|
|
# ¿ Apr 29, 2024 09:37 |
|
Jose Cuervo posted:Got it, thanks! And remember, in Python 3.6, dicts are now ordered. Python Changelog posted:New dict implementation
|
# ¿ Mar 14, 2017 21:55 |
|
Pissing me off today: back porting scripts to support RHEL5. Just, like, basic poo poo is missing from python 2.4 that I rely on all the time. Set comprehensions, any(), conditional expressions, argparse! We've still got about 20% of our infrastructure running on this 10 year old OS. At least it's Friday.
|
# ¿ Mar 24, 2017 22:45 |
|
Thermopyle posted: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. This is the perfect use case for Flask. You don't need the bells and whistles of Django. Python code:
|
# ¿ Mar 31, 2017 17:28 |
|
xpander posted:Echoing the other replies that Flask/Django are perfect for this. On the operational side, check out Zappa for some sweet serverless action. This will let you use some AWS services(API Gateway, Lambda) to run the application code without having to keep a server online. You'll fall well within the free tier for development usage, and probably well into their production load as well. How do you trigger local raspberry pi functions with Lambda?
|
# ¿ Apr 1, 2017 06:15 |
|
I've been reading Fluent Python based on this thread and Eela6's recommendation. Is there a better/more Pythonic way to do this? I'm parsing 'yum list <package>' for Installed and Available packages.code:
Python code:
|
# ¿ Apr 7, 2017 20:55 |
|
HardDiskD posted:I'd indent the other conditions and invert the any to get rid of the pass, otherwise it looks fine to me. Fluent Python has got me looking for tricks everywhere! Python code:
|
# ¿ Apr 7, 2017 22:01 |
|
onionradish posted:You can even drop the list brackets within any() as most functions that take an iterable work with a generator expression too in 3.x: I'm working with minimum python 2.4. I even have to implement my own any. Tigren fucked around with this message at 23:58 on Apr 7, 2017 |
# ¿ Apr 7, 2017 22:22 |
|
breaks posted:1) There is a potential future problem that results from the string literals being duplicated in two different places. Guess I should have posted more of the code: Python code:
2. package_name won't be seen before either of the strings, but if it is, add_to is set to available to start. 3. So I don't capture lines that don't have one of those three allowed strings. My user will pass in a package_name and get a list of available and installed packages matching that name.
|
# ¿ Apr 8, 2017 02:10 |
|
chutwig posted:If you have a long list of strings, like Yep, that's where I'd go too. code:
|
# ¿ Apr 15, 2017 00:51 |
|
Vivian Darkbloom posted:Confused about an issue with passing functions. This might be related to tkinter weirdness, but I might just be doing something else wrong. IMO, if you're going to be learning the GUI library from scratch you'd be much better served going with a small Flask app and learning the basics of HTML/CSS/JS. That's an actual marketable skill with virtually infinite learning resources vs some weird, arcane language on top of a language that produces interfaces from 1995.
|
# ¿ Apr 26, 2017 15:33 |
|
QuarkJets posted:These descriptions both describe Flask Touche. But you're not going to find a lot of employers impressed by your Tcl/Tk skills.
|
# ¿ Apr 27, 2017 02:01 |
|
Awesome, thanks for the heads up. I really wish my company would send me to PyCon, or at least not make me use vacation days to go. I look forward to the videos every year and often go back and find valuable talks from years past. I watched Tim Head's talk on MicroPython, which I've tried out before and really enjoyed. The talk made me want to sink my teeth into microcontrollers again. I've been meaning to do something with a bird house camera. I'm also excited to see a few talks on async, which seems like something I should become more familiar with in TYOOL 2017. Kelsey Hightower's Kubernetes for Pythonistas also looks like a great talk.
|
# ¿ May 22, 2017 05:58 |
|
LochNessMonster posted:Practical example question about working with functions. Sounds like what you want is a Session. http://docs.python-requests.org/en/master/user/advanced/#session-objects quote:The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3's connection pooling. So if you're making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see HTTP persistent connection). Tigren fucked around with this message at 22:26 on Jun 2, 2017 |
# ¿ Jun 2, 2017 22:23 |
|
outlier posted:A Flask question, maybe just a style one. Like Thermopyle said, you want to use a cache for this. Depending on what kind of traffic your Flask app will see, you can either use memcached or Werkzeug has a built in SimpleCache object.
|
# ¿ Aug 7, 2017 16:17 |
|
Hughmoris posted:Does anyone have any good examples/blogs/libraries using functional programming in Python? https://www.dontdoit.com
|
# ¿ Oct 27, 2017 01:39 |
|
Mr Crucial posted:I'm not sure if this is the right place for this question, but here goes. How do I add a CA certificate so that Python and Python-based apps trust TLS certs generated by that CA? I haven't used this authentication method myself, but do the following host vars help? code:
Tigren fucked around with this message at 18:12 on Nov 30, 2017 |
# ¿ Nov 30, 2017 18:10 |
|
Mr Crucial posted:They don't unfortunately, because I'm not using certificate authentication, I'm using CredSSP auth over HTTPS which is a different matter. I did try adding the ansible_winrm_cert_pem like so, but it didn't work: Does setting the REQUESTS_CA_BUNDLE environment variable help? It looks like CredSSP auth is handled by requests-credssp. I love that Ansible even just tells you to ignore cert validation. Super secure! quote:When the Ansible controller is running on Python 2.7.9+ or an older version of Python that has backported SSLContext (like Python 2.7.5 on RHEL 7), the controller will attempt to validate the certificate WinRM is using for an HTTPS connection. If the certificate cannot be validated (such as in the case of a self signed cert), it will fail the verification process. Tigren fucked around with this message at 20:53 on Nov 30, 2017 |
# ¿ Nov 30, 2017 20:35 |
|
Hughmoris posted:I'm new to Pycharm and utilizing virtual environments, and I'm running Windows 10. Phone posting, but you should be able to open the project interpreter settings and install packages there. https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html
|
# ¿ Dec 2, 2017 00:48 |
|
Hughmoris posted:Thanks. That was the initial route I pursued but the package I needed wasn't in the available list. Weird, works for me. What is listed when you click on that "Manage Repositories" button? Mine has https://pypi.python.org/simple listed.
|
# ¿ Dec 2, 2017 01:33 |
|
Hughmoris posted:How is python+selenium for filling out lots of repetitive forms? I noticed that some people on my project team are manually entering in the data for 2000+ users in to a web portal. They've asked for help but my eyes will fall out of my head if I have to manually type in crap. Do you think you could simplify this even more by just making a bunch of POST requests? See if you can spy on the transaction in Chrome Dev Tools. [Edit] Oh, another page...
|
# ¿ Dec 5, 2017 04:23 |
|
Tigren posted:And remember, in Python 3.6, dicts are now ordered. This seems like it's no longer just an implementation detail, but Guido proclaiming dicts are now ordered by design starting in 3.7. Guido van Rossum posted:Make it so. "Dict keeps insertion order" is the ruling. Thanks!
|
# ¿ Dec 20, 2017 00:27 |
|
You might also want to look into Folium. It's a quick, easy way to build a slippy LeafletJS based map using OpenStreetMap tiles from Python. https://folium.readthedocs.io/en/latest/quickstart.html#getting-started
|
# ¿ Jan 2, 2018 19:46 |
|
Hadlock posted:Is there a package/library similar to Go's "Cobra"? Command line flagging coffee organizational thing. I'm not sure you're gonna find something exactly like cobra, but maybe check out Click Python code:
Bash code:
|
# ¿ Jan 30, 2018 21:10 |
|
SnatchRabbit posted:Crossposting from the AWS thread but I'm a Python noob and I'm trying to parse some JSON data inside a notification event. What are you hoping for the end result to be? message = json.loads(message) returns a dict, and printing it will display the whole thing as a string.
|
# ¿ Mar 30, 2018 00:29 |
|
Thermopyle posted:Python 3.7 out. Love this part: quote:The Order of Dictionaries Is Guaranteed
|
# ¿ Jun 28, 2018 18:17 |
|
|
# ¿ Apr 29, 2024 09:37 |
|
Bundy posted:MariaDB and I think postgres let you easily implement versioning on tables. I personally go to json, SQL and toml for most of my needs. If it's a simple CRUD app and you don't need truly high concurrency, and you need a DB, use sqlite. It's a single file, which can of course be versioned. There's also sqldiff which lets you diff two sqlite databases. If you don't need an RDBMS, then just store your poo poo in a json file. Even if you don't need a relational DB, use sqlite. There are times when it's even faster than writing to the filesystem.
|
# ¿ Mar 22, 2019 23:50 |