|
spankweasel posted:For debugging strings, you can use %r to print the raw string: There is a little more going on here than first meets the eye. Objects have both a "str" and a "repr" method. The first gives a string representation of the object, usually focused being concise and human readable - like toString, if you come from java. In contrast, repr generally gives a string representation of the object suitable for recreating that object totally; it shouldn't leave anything out. The object class defines a repr method which prints out the class name and the location in memory (using the id builtin function). The results of repr is what you see in interactive mode when you give the interpreter an expression consisting of just an object: code:
And finally, the %r format specifier basically tells python to use repr when interpolating/formatting the object into the string, rather than str (which is what %s means). Also secret python protip: backticks around an expression means call repr() on it. No one ever uses them. tripwire fucked around with this message at 00:57 on Oct 7, 2011 |
# ? Oct 7, 2011 00:54 |
|
|
# ? Jun 12, 2024 14:13 |
|
tripwire posted:Also secret python protip: backticks around an expression means call repr() on it. No one ever uses them.
|
# ? Oct 7, 2011 03:13 |
|
Does anyone have any advice for finding good projects to work on? I've been trying to think of a good idea for literally years but can never think of anything. I want to find some cool project that people would actually use directly (probably a website), rather than contributing to a platform project like Django or whatever. I think the answer is "stop being so picky" but hey, I might as well ask. Edit: I found this, but it's totally dead. http://idk.codeplex.com/ posted:Every other month, IDK asks people to come up with their best ideas for new programs and websites. At the end of the month, everyone goes to work, and we bring our best ideas to life. Have a great idea? Let IDK build it for you. raymond fucked around with this message at 07:40 on Oct 8, 2011 |
# ? Oct 8, 2011 07:33 |
|
start working on an existing project, then you'll find a million things you wish existed that don't.
|
# ? Oct 8, 2011 16:45 |
|
TasteMyHouse posted:start working on an existing project, then you'll find a million things you wish existed that don't. This is so true.
|
# ? Oct 8, 2011 16:57 |
|
raymond posted:Does anyone have any advice for finding good projects to work on? I've been trying to think of a good idea for literally years but can never think of anything. This came up earlier in the thread I think, but a good place to start is your everyday work. What's something you have to do a lot that you wish was automated? Make it so. Use the 10 minute rule: if something takes more than 10 minutes and you have to do it more than once, you should write some code that takes care of it for you. vvvvvv Hahaha....sorry, this is pretty elementary advice! FoiledAgain fucked around with this message at 03:54 on Oct 9, 2011 |
# ? Oct 8, 2011 19:15 |
|
TasteMyHouse posted:start working on an existing project, then you'll find a million things you wish existed that don't. FoiledAgain posted:This came up earlier in the thread I think, but a good place to start is your everyday work. What's something you have to do a lot that you wish was automated? Make it so. Use the 10 minute rule: if something takes more than 10 minutes and you have to do it more than once, you should write some code that takes care of it for you. I might look into freelance work, I guess.
|
# ? Oct 9, 2011 02:47 |
|
raymond posted:Absolutely, but my problem is finding a project! Since you're a full-time Python dev, why not look into making existing tools better: pylint - add a feature to fix some/most/all of whatever inane bullshit it thinks is wrong with your code (hurr this method has too many conditional statements!) pep8 - add a feature to fix discovered errors (this has been done already by a fork of the project, but write up a patch for the original guy) nose - add features to nose that you need for testing. mercurial - write a useful hook or help fix what mercurial currently uses (I have no idea how popular hg actually is, but it's what my shop uses. I guess all the cool kids use git now or something.) python - find and fix bugs in python itself. They have a huge need for unittests among many many MANY other things.
|
# ? Oct 9, 2011 03:17 |
|
raymond posted:Does anyone have any advice for finding good projects to work on? I've been trying to think of a good idea for literally years but can never think of anything. I want to find some cool project that people would actually use directly (probably a website), rather than contributing to a platform project like Django or whatever. Fork boa constructor, and bring it back from the dead. Seriously. If I had time I would do it. Its the best python RAD ide ever, but it suffers terrible dependency rot at the moment. Its basically delphi but with python. But it was a one man job and I think he gave up a bunch of years ago. duck monster fucked around with this message at 10:14 on Oct 10, 2011 |
# ? Oct 10, 2011 10:12 |
|
While I do very much appreciate the suggestions, I can't get excited about writing dev tools in my spare time. I do enough laborious development at work, so a home project needs to be fun. I'll just keep watching TV shows and playing video games while hopelessly trying to think up the next Twitter or Reddit (minus the CP).
|
# ? Oct 11, 2011 10:11 |
|
raymond posted:While I do very much appreciate the suggestions, I can't get excited about writing dev tools in my spare time. I do enough laborious development at work, so a home project needs to be fun. I'll just keep watching TV shows and playing video games while hopelessly trying to think up the next Twitter or Reddit (minus the CP). You really have 2 options. 1) Flashy graphical things which can offer quick feedback for your effort and fun optimisation problems. Try writing a tunnel raytracer in Python, aim for 60fps :-) 2) Tools. Try and find something you need and implement it. Probably the tool I'm most proud of making is Xawk https://github.com/SteveJones/xawk. It's really lovely but it's surprisingly useful. Maybe one day I'll finish it. curl 'http://forums.somethingawful.com/' | ./hawk -e '//a[@class="forum"] { print text() " - " @title; }' Gets you a list of the top level sub forums. Zombywuf fucked around with this message at 10:35 on Oct 11, 2011 |
# ? Oct 11, 2011 10:33 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:23 on Mar 13, 2017 |
# ? Oct 14, 2011 01:21 |
|
GregNorc posted:Hi. I'm a bit of a python newbie. I use it mostly to clean files before I do stat work in them in R. argv[0] is the name of your script, not the first argument. http://docs.python.org/library/sys.html#sys.argv
|
# ? Oct 14, 2011 01:25 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:23 on Mar 13, 2017 |
# ? Oct 14, 2011 01:35 |
|
TasteMyHouse posted:You're making things harder on yourself by using Python 3 (and windows...)
|
# ? Oct 14, 2011 02:20 |
|
MC Fruit Stripe posted:Are the two so incompatible? Would one be better off learning Powershell, or any other alternative, rather than Python, if they intend to use it in a Windows environment? I personally love python, and it isn't actually that bad on Windows. I was just being an OS snob Learn powershell if your goal is to Command Windows. learn python if you want to write software.
|
# ? Oct 14, 2011 02:30 |
|
GregNorc posted:I run "python oneDigit.py raw.csv", which loads "raw.csv" and basically outputs the contents after running a regex to strip out useless whitespace. since you're actually doing work with those csv files instead of just doing some tutorials, python's csv module is really useful and may be worth considering depending on what exactly you're doing with regular expressions. And if you ever get data in excel format, there's also xlrd
|
# ? Oct 14, 2011 03:38 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:23 on Mar 13, 2017 |
# ? Oct 14, 2011 03:51 |
|
I apologize if this gets asked a lot but I skimmed a bit a didn't see anything. I'm looking for a simple and preferably cheap way to host Python webapps. I've never done web dev in Python, just PHP, and I'm looking to start playing around with Python on the web and trying flask. I used to have hosting through a friend (using a LAMP stack) but he shut down his servers. I tried using AWS and doing all of the admin stuff myself but after fighting with fastcgi config on lighttpd for a while I give up. I have a domain, dns hosting, etc already I just want something I can use to deploy python webapps with as little headache as possible. Any suggestions are appreciated. I've been recommended heroku, dotcloud, and google app engine but all by people who have heard good things about them, not from people who have used those services, so some hands on opinions would be great.
|
# ? Oct 14, 2011 18:42 |
|
I have a barebones VPS over at Rackspace Hosting (formerly slicehost), and I although I don't actually do much with it I found it very easy to get up to speed. I'm more comfortable installing things for myself with yum/apt on the command line, and if that sounds ok, it's hard to get any easier
|
# ? Oct 14, 2011 20:10 |
|
Has anyone know where I can get a prebuilt version of psycopg2 and the various geodjango binary bits for Lion. This loving upgrade (which I had to do to use the latest xcode for work) has blown away my python site-packages directory (!!!) and for the loving life of me I cant work out how to do this since I have no idea where to find the Python.h (etc) relevant to my Lion python2.7 install, or for that matter how to tell easy_install where it is. e: Hmm seems like that xcode install didn't take. Trying again... duck monster fucked around with this message at 11:24 on Oct 17, 2011 |
# ? Oct 17, 2011 09:52 |
|
duck monster posted:Has anyone know where I can get a prebuilt version of psycopg2 and the various geodjango binary bits for Lion. This loving upgrade (which I had to do to use the latest xcode for work) has blown away my python site-packages directory (!!!) and for the loving life of me I cant work out how to do this since I have no idea where to find the Python.h (etc) relevant to my Lion python2.7 install, or for that matter how to tell easy_install where it is. I had a lot of luck with macports. Just remember that you want 2.7 then tell it "py27-" every time. Once I'd used it to install setuptools then easy_install worked fine.
|
# ? Oct 17, 2011 10:27 |
|
Ugh. This is a loving mess. I'm going to try and restore my old 2.6 dir from time machine. *shudder* e: haha gently caress you lion I win. It worked. Time machine owns. duck monster fucked around with this message at 12:31 on Oct 17, 2011 |
# ? Oct 17, 2011 12:24 |
|
rivals posted:I apologize if this gets asked a lot but I skimmed a bit a didn't see anything. I'm looking for a simple and preferably cheap way to host Python webapps. I've never done web dev in Python, just PHP, and I'm looking to start playing around with Python on the web and trying flask. I used to have hosting through a friend (using a LAMP stack) but he shut down his servers. I tried using AWS and doing all of the admin stuff myself but after fighting with fastcgi config on lighttpd for a while I give up. I have a domain, dns hosting, etc already I just want something I can use to deploy python webapps with as little headache as possible. Any suggestions are appreciated. I've been recommended heroku, dotcloud, and google app engine but all by people who have heard good things about them, not from people who have used those services, so some hands on opinions would be great. Amazon AWS is excellent. Plus you will probably be able to fit in their free usage tier (http://aws.amazon.com/free/). I've used Google App Engine, and it's nice, but if you're just getting started with Python development I wouldn't recommend it -- stay vanilla, use AWS.
|
# ? Oct 17, 2011 18:12 |
|
Webfaction is prety good for cheap hosting,
|
# ? Oct 18, 2011 02:10 |
|
I want to learn to use Python to help with website analytics. Data collection and analysis from Google Analytics, KISSmetrics, Mixpanel, Optimizely, etc. I'm confident my needs are fairly straightforward. What is the best way/source to learn Python with this need in mind? I've browsed some options, and right now I'm attracted to Learn Python the Hard Way, but I worry that it focuses mainly on building small applications rather than querying something like Google Analytics for the kind of data I need. Then again, maybe everybody including me needs those basic skills, or maybe writing those kinds of mini-apps is exactly what I need to be doing and I just don't understand that. My experience with coding is rudimentary, please forgive any misapprehensions re. what I need to learn. I'd like to learn as quickly as possible, but I'm not under the delusion that I'll get this down in just a couple days with near-zero prior experience.
|
# ? Oct 18, 2011 17:00 |
|
Chimp_On_Stilts posted:I want to learn to use Python to help with website analytics. Data collection and analysis from Google Analytics, KISSmetrics, Mixpanel, Optimizely, etc. I'm confident my needs are fairly straightforward. What is the best way/source to learn Python with this need in mind? There is nothing that would teach you anything geared towards what you want...that doesn't even really make any sense. You just need to learn Python. Period. From what I understand Python the Hard Way is a fine place to start.
|
# ? Oct 18, 2011 19:37 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:23 on Mar 13, 2017 |
# ? Oct 18, 2011 20:50 |
|
You can do it simpler than that:code:
|
# ? Oct 18, 2011 21:03 |
|
GregNorc posted:Let's say I have a list of five integers. For sake of simplicity, l = [1,2,3,4,5] code:
edit: fixed tables
|
# ? Oct 18, 2011 21:14 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:24 on Mar 13, 2017 |
# ? Oct 18, 2011 21:14 |
|
GregNorc posted:Thanks... You can use my solution above and just sort the tuple you're checking and use that as a key. Or you can key it on the sum instead, though multiple combinations could have the same sum, which would make it a little different ...
|
# ? Oct 18, 2011 21:16 |
|
EDIT: dang, so slow. if you actually care about seeing all the different combinations, something like this should get you there: code:
|
# ? Oct 18, 2011 21:16 |
|
Sailor_Spoon posted:EDIT: dang, so slow. You don't need to check |a|+1, as C(n,k)=0 for k>n. Otherwise, this code should be exactly what GregNorc wants. There's no specific phrasing to it -- it's just a plain ol' combination without repetition.
|
# ? Oct 19, 2011 00:57 |
|
Kim Jong III posted:You don't need to check |a|+1, as C(n,k)=0 for k>n. the +1 is to pull in the original since range is not endpoint-inclusive
|
# ? Oct 19, 2011 01:28 |
|
I am trying to figure out how to structure my Python application. It is basically a whole bunch of producers and workers which I need to keep up and running indefinitely. The way I saw this working was to create a 'supervisor' script that I would run as a daemon or using upstart. This supervisor will somehow spawn the all the producers and workers, potentially as sub processes? I need to create it in such a way so if I was to stop the supervisor process, it will shut down all the spawned processes first before exiting. I'd also like to be able to implement some kind of event/messaging system using a broker. What I'd like to be able to do is listen for system wide events on the supervisor and then communicate the event to the relevant sub process. Can anyone tell me how I can go about achieving this? Is using a singular supervisor script with spawned sub processes correct or am I missing something?
|
# ? Oct 19, 2011 13:53 |
|
No Safe Word posted:the +1 is to pull in the original since range is not endpoint-inclusive Man, the fact that range is closed on the left and open on the right always screws me up... and I've been using Python for years now.
|
# ? Oct 19, 2011 14:00 |
|
Kim Jong III posted:
this has never bothered me, because it's the same way the standard for loop works in C-derived languages (i.e. using <, and not <=)
|
# ? Oct 19, 2011 14:07 |
|
Hanpan posted:I am trying to figure out how to structure my Python application. It is basically a whole bunch of producers and workers which I need to keep up and running indefinitely. Check out Supervisor for a pre-rolled solution.
|
# ? Oct 19, 2011 15:13 |
|
|
# ? Jun 12, 2024 14:13 |
|
I decided to learn some Python with Pygame (I have little to no real programming experience), and I downloaded this off of the pygame web page. I got the the fourth "chapter", where pygame gets introduced, and every time I use pygame to open up a window, it crashes when I close it (hangs/becomes unresponsive/I have to task manager it). This is only through IDLE though, when I run the file straight through python, it works fine (basically). This is my code (basically lifted straight out of the pdf): code:
|
# ? Oct 19, 2011 20:53 |