I'm very curious about Python. I've never used it, but can't help but see everybody praising it, while everybody puts down PHP. I figured I might as well give it a whirl, but I was wondering if anybody had a good comparison of how something is written in PHP vs what the equivalent would look like in Python, specifically geared towards web development.
|
|
# ¿ Feb 26, 2008 02:13 |
|
|
# ¿ May 14, 2024 18:21 |
duck monster posted:PHP is however a pretty focused little web language, but not really that good for much else, in comparison with other languages. What makes it not as good as python for a command line application? I've only done very basic things on the command line with php, but Python looks like it would be a lot more useful since it has GTK support.
|
|
# ¿ Feb 26, 2008 05:27 |
I've decide to re-write a PHP webapp in Python since the PHP code is crap and I've been wanting to learn Python for awhile anyways. I was going to give Flask & SQLAlchemy a shot, seems to offer a bit more flexibility over something like Django. Any advice before I dive in?
|
|
# ¿ Feb 23, 2012 21:26 |
Perfect timing for the sale! My PyCharm trial was just about to run out.
|
|
# ¿ Dec 21, 2012 04:56 |
What do you guys typically use for a production stack? apache2? gunicorn? nginx out in front of those? How do you handle deployments to a production environment?
|
|
# ¿ Aug 8, 2013 19:28 |
deimos posted:@jesseenoller (the OP iirc) asked exactly this on twitter today, general answer seems to be: I've been meaning to learn how to use chef. Been playing around with it for the past couple hours and it is really neat. One question though, and this may not be the right thread for it, but how do I get the code for my app onto the server using chef? The code is in a remote git repo...should I use git to download the code in my chef recipe? I'm sure there's a million different ways this could be answered, just looking for something basic and sensible for now. edit: This sounds like the answer to my question: http://docs.opscode.com/resource_deploy.html fletcher fucked around with this message at 06:37 on Aug 9, 2013 |
|
# ¿ Aug 9, 2013 04:48 |
Trying to set up a new machine but I'm running into an error when I try to run the south migration. It seems to work fine on my dev machine running Mint, but when my chef recipe gets to this step on Ubuntu Server 12.04 it hits an error. Any ideas?code:
fletcher fucked around with this message at 20:46 on Aug 9, 2013 |
|
# ¿ Aug 9, 2013 20:29 |
If you install something like uWSGI in a virtualenv, should any configuration files also live inside the virtualenv?
|
|
# ¿ Aug 13, 2013 07:40 |
I've got a form that allows somebody to upload a CSV file, and then I want to read it and display it back to them so they can enter some additional information about what is in each column. What sorts of things do I need to be concerned about for validating the file and displaying it back to them? I was looking at csvvalidator but it seems to be more geared to already knowing the structure of the CSV, which I will not know. Also looked at python-magic but the first random CSV I tried it on came back as assembler source, UTF-8 Unicode text, so that didn't seem like the way to go. So should I just not do any validation before loading it up with unicodecsv? I was just gonna make the assumption that it's UTF-8 encoded, reliably detecting the encoding seems like a big pain in the rear end.
|
|
# ¿ Oct 1, 2013 22:36 |
Dren posted:What things do you want to validate? I dunno, I'm always paranoid about anything user supplied, and trying to prevent them from causing any harm. I suppose all I can do in this case is make sure I can read the whole file with UTF-8 encoding, and let them know if there was a problem.
|
|
# ¿ Oct 2, 2013 00:21 |
QuarkJets posted:I was given a Macbook Pro at my work, and after about a month of trying to develop on it I gave up and installed an RHEL6 virtual machine. I've never looked back. OSX is just not a very good code development environment, especially if you're coming over from Linux. It's probably pretty good if you're coming over from Windows. I wouldn't wanna do dev work on my host OS anyways. There are just sooo many benefits to using virtual machines for everything, even if my host OS was my preferred OS to do dev work in, I'd still use virtual machines.
|
|
# ¿ Oct 11, 2013 22:30 |
What's an easy way to strip exif data from an image?
|
|
# ¿ Oct 11, 2013 23:13 |
Dren posted:What kind of image? jpeg? I hadn't really thought about other image formats, I thought it was only jpg that supported exif data. I came across exiftool in my searching but I was hoping for something that was pure python. I suppose I'll use it anyways though. The purpose is just to strip exif data from user uploaded images, don't wanna be distributing GPS coordinates when they upload photos from their phone. Thanks!
|
|
# ¿ Oct 12, 2013 02:36 |
Interesting...I'm using PIL to read the exif data, I didn't realize you could edit it as well. How do you do that?
|
|
# ¿ Oct 12, 2013 02:41 |
Is there an easy way to crop and resize animated gifs in Python? I found images2gif but I'm wondering if there's something that's...a little better supported. Maybe I'm better off going with some external utility like ImageMagick?
|
|
# ¿ Oct 30, 2013 23:50 |
fletcher posted:Is there an easy way to crop and resize animated gifs in Python? I found images2gif but I'm wondering if there's something that's...a little better supported. Maybe I'm better off going with some external utility like ImageMagick? To answer my own question from earlier...I think I'm gonna go with gifsicle to do this. I couldn't get imagemagick to crop an animated gif without mangling it. Gifsicle seems to do it no problem.
|
|
# ¿ Nov 13, 2013 21:15 |
the posted:Not sure, but I did a ghetto work-around by just editing the file that I created within python and then using that to read from. Turn on display of file extensions! I find myself compulsively changing that setting as soon as I sit down a computer that isn't my own.
|
|
# ¿ Nov 15, 2013 23:44 |
My IDE suggested I rewrite my conditionalcode:
code:
|
|
# ¿ Nov 19, 2013 02:39 |
Opinion Haver posted:But that has different behavior if key is not in mydict. It's a boolean, doesn't always have to be in mydict though. Variable name corresponds to a field on a REST API. If it's not specified (key does not exist in mydict), I don't want it to # do stuff. From the replies it sounds like the IDE is suggesting something that is not a logic neutral change.
|
|
# ¿ Nov 19, 2013 03:02 |
Suspicious Dish posted:If you want to compare against a boolean explicitly, always use foo is False, as lots of things can compare to False that aren't actually False. Ahh that makes sense, thanks!
|
|
# ¿ Nov 19, 2013 03:12 |
Red Robin Hood posted:I have nearly 0 coding experience. I've done a fair bit of HTML, some CSS, and basic batch file scripting. Dabbled with PowerShell. Yes, definitely!
|
|
# ¿ Nov 21, 2013 07:48 |
Python code:
|
|
# ¿ Dec 3, 2013 01:50 |
FoiledAgain posted:You could put this in its own module and then do from thingy import cached_expensive_stuff. My example might be a little too simplified. There's other attributes in Thingy() that are used in get_expensive_stuff, so I thought it made sense to make it a method on Thingy()
|
|
# ¿ Dec 3, 2013 01:58 |
Mr. Wynand posted:Do you mean automating caching? That's more of a ruby thing to do (), but there is actually a memoization decorator in Python 3's functools module (lru_cache). Yup, I had a feeling Python might have something fancy like that lru_cache. I'm still on 2.7 so I won't go down that route just yet. Thanks for the feedback!
|
|
# ¿ Dec 3, 2013 02:13 |
Mr. Wynand posted:PS: make sure it's "class Thing(object):" - when you don't inherit from "object" you are defining "old style classes" which is a deprecation measure you should steer clear of. Ah good to know. It's actually a Django model so it inherits from models.Model. I haven't actually declared any of my own classes yet outside of those models, but I will keep that in mind.
|
|
# ¿ Dec 3, 2013 02:15 |
Haystack posted:Lifted more or less unmolested from Pyramid's source Well that's pretty drat slick, I don't quite understand everything going on in there though. What's it doing with __doc__?
|
|
# ¿ Dec 3, 2013 02:34 |
That was a great post to read, well done I think I'll stick with the if statement for now.
|
|
# ¿ Dec 3, 2013 07:24 |
fletcher posted:
After reading about this a bit more, I'm a little confused. I was thinking cached_expensive_stuff = None was initializing an instance variable, not a class variable. I don't want different instances of Thingy using the same cached_expensive_stuff. But from my test, it doesn't seem like they are using the same cached_expensive_stuff, so it works like I intended? Python code:
code:
|
|
# ¿ Dec 4, 2013 02:45 |
Pollyanna posted:Tried to take the Python test on E-Lance and I couldn't even get past the first question Don't get so down on yourself and keep practicing. It takes time to build up the mental toolbox of things you can use to solve problems. You aren't alone in experiencing these frustrations. You do yourself a disservice though if you don't learn from these moments! Sometimes for those types of problems, it's better to just bust out a pen and paper and play around with the numbers to figure out how your program might work.
|
|
# ¿ Dec 12, 2013 21:19 |
http://flask.pocoo.org/docs/templating/#controlling-autoescaping
|
|
# ¿ Dec 17, 2013 03:05 |
Pollyanna posted:Version 1.1 of my app is up, too! Woohoo! Way to go!! Pollyanna posted:
#1 Maybe use a try/except and catch the IOError (should be caught anyways when communicating to external services in case they go down) #2 I think you want request.args, haven't used Flask before though #3 Probably a way to avoid generating an actual file each time, not familiar with that library though. Should be able to just stick it inside of a <script type="text/javascript">alert('hello world')</script> type of thing. If it turns out you have to actually generate a file, use a randomized filename so you don't run into an issue where two requests try to write to the same embed.js file each time (and make sure they are temp files so they get automatically cleaned up)
|
|
# ¿ Dec 21, 2013 01:03 |
Pollyanna posted:I don't know what happened since I started working on v1.2, but now SA keeps flashing "hello world" alert boxes at me Hmmm that's not good...XSS vulnerability on here? I'm not getting any alerts on this page.
|
|
# ¿ Dec 21, 2013 09:33 |
Dominoes posted:I love how easily cross-platform Python and its tools are. I've been in a transient period for the past three months, using a laptop with Ubuntu. Since then, I picked up some new habits like using Git, Pycharm,IPython etc. To transition back to the Windows desktop, all I had to do was copy and past my code folder, and install git/pycharm/ipython. My programs and Django apps run with no additional configuration, PyCharm looks the same after setting up the fonts, and it recognizes my Qt etc modules now. But why would you wanna develop on Windows?? Install an Ubuntu VM on your desktop
|
|
# ¿ Dec 23, 2013 20:25 |
Little test program:code:
code:
I have a function that generates a bunch of CoolObjects and returns a list, but as I'm generating them I don't want to add them to the list if a duplicate is already in there. Is overriding __eq__ the correct way to handle 'x in somelist' and 'x not in somelist' behavior?
|
|
# ¿ Jan 14, 2014 02:17 |
In case it's at position 0:code:
|
|
# ¿ Jan 14, 2014 08:29 |
That one is probably more suited to the Web Development megathread, may want to ask over there and provide some sample code. I have a question about the Image.save() method in PIL/Pillow. I see examples of code using arguments like quality and optimize, but I can't find any details about what they do or how they work in the documentation. Where can I find out more details about them?
|
|
# ¿ Jan 21, 2014 02:11 |
Is there any way to set the max number of http retries that a pip install will attempt? I keep getting this error trying to grab stuff off s3 from ec2:quote:Max retries exceeded with url: /pypi/uwsgi-1.9.18.2.tar.gz (Caused by <class 'httplib.BadStatusLine'>: It seems odd that I can't reproduce it with this though: code:
|
|
# ¿ Jan 31, 2014 20:03 |
Is there an easy way to see which packages are depending on package <x> in a virtualenv?
|
|
# ¿ Feb 24, 2014 22:23 |
accipter posted:You could try this: That seems to work but only going the other direction: code:
code:
|
|
# ¿ Feb 25, 2014 00:04 |
|
|
# ¿ May 14, 2024 18:21 |
SurgicalOntologist posted:I'm annoyed by Pycharm's inspection of example code in docstrings (detected by >>>). For example, I have this docstring segment: Is that using the latest version of PyCharm? I do see several bug reports that sound like what you are describing. This one was closed as a wontfix - is your docstring the first statement in the function?
|
|
# ¿ Feb 25, 2014 18:15 |