|
HatfulOfHollow posted:I'm pretty sure this replaces that entire monstrosity... I was bored, so I took a shot at it too. Seems to work well enough from my quick testing... code:
|
# ? Aug 12, 2009 22:18 |
|
|
# ? May 9, 2024 14:30 |
|
You people and your making me look bad. I'll have a look over those, and if they work, I love you. Even if they don't I appreciate the effort. Thanks, really. Any ideas why it stopped before the end, or should I just chalk that up to I suck at python and it got angry at that? E: Just checked, both are perfect; I'm indebted to you. TheMaskedUgly fucked around with this message at 00:42 on Aug 13, 2009 |
# ? Aug 12, 2009 23:59 |
|
Lonely Wolf posted:It looks like it's running fine except you didn't pass it any command line arguments and you're running it on windows instead of a *nix. There does not appear to be a problem. What do you think is wrong? Yeah it seems you're right. It wasn't printing 'We are arguments' when I ran or imported it so I figured that I just totally hosed everything up. Since that dumb question is dealt with, I have another (possibly more stupid. I'm pretty poo poo with computers): In this lesson the guy codes a basic backup program and uses his OS's built-in 'zip' function to zip the files. On the previous page he recommends getting Info-Zip for Windows users. I tried that and ZLib but I'm totally lost when I try to use them with Python. If anyone could steer my dumb rear end on track it'd be appreciated.
|
# ? Aug 13, 2009 01:08 |
|
TheMaskedUgly posted:You people and your making me look bad. I'll have a look over those, and if they work, I love you. Even if they don't I appreciate the effort. Thanks, really. That's actually surprising. I didn't even test mine. I wrote it in notepad after tracing the original script in my head. I'm a badass.
|
# ? Aug 13, 2009 01:15 |
|
TheMaskedUgly posted:You people and your making me look bad. I'll have a look over those, and if they work, I love you. Even if they don't I appreciate the effort. Thanks, really. I didn't bother to check but if you want to, check out the python debugger. It's included with python and you can see instructions on how to use it here: http://docs.python.org/library/pdb.html Try setting a breakpoint before where it breaks and stepping through the code line by line to see whats up. Alternatively, since you can run python interactively from a shell, try doing it that way and take advantage of the read-eval-print loop to check the values of variables and so on at your leisure.
|
# ? Aug 13, 2009 02:21 |
|
HatfulOfHollow posted:That's actually surprising. I didn't even test mine. I wrote it in notepad after tracing the original script in my head. I'm a badass. Yeah but mine calls strip() so it doesn't embed extra newlines.
|
# ? Aug 13, 2009 15:17 |
|
NadaTooma posted:Yeah but mine calls strip() so it doesn't embed extra newlines. creating a working script without testing > using strip()
|
# ? Aug 13, 2009 15:26 |
|
tripwire posted:I didn't bother to check but if you want to, check out the python debugger. It's included with python and you can see instructions on how to use it here: http://docs.python.org/library/pdb.html alternatively winpdb is a good multi-platform python debugger. i use it all the time. http://www.winpdb.org/cgi-bin/moin.cgi/WinpdbTutorial compuserved fucked around with this message at 19:24 on Aug 13, 2009 |
# ? Aug 13, 2009 19:21 |
|
Threep posted:I'm working on something that involves downloading a queue from a small number of different connections (say, 5 or so) to different files Twisted! Anything else is just dumb. (Short of reimplementing twisted yourself, which is dumb for other reasons.) Threading would just add a lot of overhead: code complexity overhead and CPU overhead both.
|
# ? Aug 13, 2009 19:37 |
|
Habnabit posted:Twisted! Anything else is just dumb. (Short of reimplementing twisted yourself, which is dumb for other reasons.) Threading would just add a lot of overhead: code complexity overhead and CPU overhead both. I can write a multi-threaded application with no problem but for some reason twisted just confuses the hell out of me. I think it's the layer of abstraction. Not seeing exactly what's going on behind the scenes makes it harder for me to understand.
|
# ? Aug 13, 2009 19:46 |
|
HatfulOfHollow posted:I can write a multi-threaded application with no problem but for some reason twisted just confuses the hell out of me. I think it's the layer of abstraction. Not seeing exactly what's going on behind the scenes makes it harder for me to understand. I've noticed the same. It makes me feel dumb.
|
# ? Aug 13, 2009 21:23 |
|
HatfulOfHollow posted:I can write a multi-threaded application with no problem but for some reason twisted just confuses the hell out of me. I think it's the layer of abstraction. Not seeing exactly what's going on behind the scenes makes it harder for me to understand. No, twisted really is just that confusing. Also camelCase, and old style classes, and like 3 other things they do just piss me off.
|
# ? Aug 13, 2009 21:51 |
|
HatfulOfHollow posted:creating a working script without testing > using strip() Hate to burst your bubble, but I did have to rename some of the classes, capitals in wrong places and whatnot. Come on man, you can do better than that. I kid, that's almost certainly my random capitalisation-ing.
|
# ? Aug 13, 2009 23:22 |
|
I hope you learned a valuable lesson about how not to code Did you end up giving pdb or winpdb a shot?
|
# ? Aug 14, 2009 00:23 |
|
http://eventlet.net/ might be an alternative to twisted
|
# ? Aug 14, 2009 00:25 |
|
Habnabit posted:Twisted! Anything else is just dumb. (Short of reimplementing twisted yourself, which is dumb for other reasons.) Threading would just add a lot of overhead: code complexity overhead and CPU overhead both. Yes. Threading adds so much complexity which twisted totally avoids because it's not complex at all. /sarcasm
|
# ? Aug 14, 2009 01:10 |
|
It's PyCon time again folks (sort of)! The call for proposals has just gone out, for any goons interested in sharing something with the Python community this is your big chance: http://pycon.blogspot.com/2009/08/pycon-2010-call-for-proposals.html
|
# ? Aug 14, 2009 01:12 |
|
m0nk3yz posted:Yes. Threading adds so much complexity which twisted totally avoids because it's not complex at all. /sarcasm At least problems in my twisted code are deterministic. And really, twisted isn't as complicated as everyone makes it out to be. There's a lot of layers of abstraction, but relatively few that you actually have to touch yourself. Look over the finger tutorial sometime; it's pretty simple.
|
# ? Aug 14, 2009 06:28 |
|
Habnabit posted:At least problems in my twisted code are deterministic. I'm pretty familiar with threading, multiprocessing, and twisted. Yes; it is complex in odd ways, and while some people think asynchronous programming is the One True Way, personally, I'm not sold on it. I've not had non-determinism problems using threading, and plenty of other people have been pretty successful using it.
|
# ? Aug 14, 2009 13:48 |
|
Speaking of twisted, does anyone have any idea why I can't get it to work anymore? Their latest release just won't work for me at all. I can import twisted, but anything more than that results in errors like "No module found names twisted.words". I've tried using the binary windows installer and python setup.py install on two different machines on WinXP SP2, SP3, and the Win7 RC, in Python 2.5, 2.6, stackless 2.5, and stackless 2.6. I'm getting by without it for now, but I'd really like it eventually! Has anyone encountered a similar problem?
|
# ? Aug 14, 2009 20:54 |
|
So I've finally gotten around to starting to teach myself game development, and I'm doing so in Python with pyglet. I'm currently working on making a simple 2D platformer for the sake of learning. I'm trying to organize my code properly so that I can keep building on top of it without it turning into a giant mess. I have almost no experience working with larger projects, and I'm sure I'm going about it in a terrible and possibly offensive way. It's organized so that I have a main game file, which imports all my classes and functions from various other files. I'm running into a problem with this, though. My Player class needs to know about the size of the game window for the purpose of collision detection, but it doesn't know about the window object since it's declared in the main game file. I have a feeling I'm doing something fundamentally wrong here. What's the proper way to go about this situation?
|
# ? Aug 18, 2009 06:04 |
|
mit_senf posted:Pass along the world/game window object to Player in the constructor?
|
# ? Aug 18, 2009 11:15 |
|
I had thought of that, but I figured there would be a better solution since it seems like there will be a lot of situations where I'd need to do this, and I think it's kind of ugly. But if that's the way to do it, then I'll do it. Thanks. Edit: On that note, as a newbie to Python, I'm not sure how to keep a pointer to the window after passing it to the player in the constructor. If I set the window as an attribute of the Player object, it'll create a new copy of the window rather than a pointer, right? dizzywhip fucked around with this message at 09:14 on Aug 19, 2009 |
# ? Aug 19, 2009 08:17 |
|
I had a similar question earlier in this thread, and I ended up instantiating the primary object and importing it into the necessary file(s)outlier posted:Note that there's nothing especially Pythonic about this problem, it's a common design issue. There's a few ways you can go around this: Lurchington fucked around with this message at 14:50 on Aug 19, 2009 |
# ? Aug 19, 2009 14:46 |
|
Does anyone know how to retrieve a line immediately before a matched line with the re module? For example, if I have the text: one two three two and I have the regular expression p = re.compile('two') can I get the lines containing the words "one" and "three" that are immediately before the matched "two"? Thanks Edit: Thank you vvvvvvvvvvvvvvvvvvvvvvv checkeredshawn fucked around with this message at 15:14 on Aug 20, 2009 |
# ? Aug 19, 2009 19:24 |
|
code:
|
# ? Aug 19, 2009 20:38 |
|
I am having a problem with unicode and webpages. I'm pulling some data from an rss feed (the source), and putting it in another blog (wordpress) effectively making an rss aggregator (the target) When i get the data from the rss, it looks like this: haven’t When i use the wordpress xml-rpc api to store the data in the target, it gets stored on the db like this: haven\xe2\u20ac\u2122t However, the xml-rpc api doesn't do what i want, so i'm manually inserting the data into the posts table, and where it is stored like this: haven\u2019t When i view it in the browser, the data uploaded via xml-rpc displays correctly, but the manually inserted data doesn't, giving me that unicode-wtf character. I'm obviously missing some voodoo somewhere but i don't know where. I have checked both the mysql server and client are using utf-8 and the webpage character set is utf-8, any ideas?
|
# ? Aug 21, 2009 21:12 |
|
Wordpress is behaving as if the database is in windows-1252 encoding, instead of UTF-8. Double-check which encoding the tables were created with. >>> u"haven’t".encode ("utf-8").decode("windows-1252") u'haven\xe2\u20ac\u2122t'
|
# ? Aug 22, 2009 02:45 |
|
I've never done web scrapping before and was wondering if anyone knew of, or had, an example of an imdb scrape? I want to learn how to do it for a few other sites but really wanted to find an example to build off of.
|
# ? Aug 22, 2009 03:45 |
|
I have a set of variables like so:code:
|
# ? Aug 22, 2009 07:40 |
|
Why not make an array to store the variables from most to least important, then loop through it until you find the first non-blank one?
|
# ? Aug 22, 2009 08:21 |
|
nbv4 posted:I have a set of variables like so: code:
|
# ? Aug 22, 2009 10:30 |
|
chemosh6969 posted:I've never done web scrapping before and was wondering if anyone knew of, or had, an example of an imdb scrape? I want to learn how to do it for a few other sites but really wanted to find an example to build off of. This guy has a pretty good guide for how to use it.
|
# ? Aug 22, 2009 12:23 |
|
outlier posted:
In python theres all sorts of crazy things you can do with things like [x.keys() for item in enumerate(list)] and lambdas and stuff. I thought there might be a better more idomatic way to do it without loops. But I guess you method works fine.
|
# ? Aug 22, 2009 18:14 |
|
nbv4 posted:In python theres all sorts of crazy things you can do with things like [x.keys() for item in enumerate(list)] and lambdas and stuff. I thought there might be a better more idomatic way to do it without loops. But I guess you method works fine. code:
|
# ? Aug 22, 2009 18:28 |
|
You can abuse variable arguments if you want:code:
code:
code:
|
# ? Aug 22, 2009 23:50 |
|
Janin posted:Wordpress is behaving as if the database is in windows-1252 encoding, instead of UTF-8. Double-check which encoding the tables were created with. hey thanks, i changed my mysql connection in python to use latin1, and run the rss content through .ecode("utf-8") and now everything seems to be working ok. i was lookng at things with show create ... the database: otntest | CREATE DATABASE `otntest` /*!40100 DEFAULT CHARACTER SET utf8 */ the table: CREATE TABLE `wp_4xgtmw_posts` ( `ID` bigint(20) unsigned NOT NULL auto_increment, ... ) ENGINE=MyISAM AUTO_INCREMENT=64 DEFAULT CHARSET=utf8 | and if i look in phpmyadmin the columns of that table are using utf8_general_ci collation. however i do see this on the server: mysql> SHOW VARIABLES LIKE 'char%'; +--------------------------+-----------------------------------------+ | Variable_name | Value | +--------------------------+-----------------------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | +--------------------------+-----------------------------------------+ 7 rows in set (0.00 sec) mysql> it's working now which is cool, but i don't understand why i need to run the rss data through .encode() (isn't it already utf8 coming from the feed?) and why i need to set the db connection to use latin1 in python.
|
# ? Aug 23, 2009 17:26 |
|
unixbeard posted:it's working now which is cool, but i don't understand why i need to run the rss data through .encode() (isn't it already utf8 coming from the feed?) and why i need to set the db connection to use latin1 in python.
|
# ? Aug 23, 2009 17:59 |
|
root beer posted:Take a look at BeautifulSoup. It has an extensive documentation and would make the task loads easier. Thanks!!!
|
# ? Aug 24, 2009 00:44 |
|
|
# ? May 9, 2024 14:30 |
|
Janin posted:You need to do both of these because Wordpress is configured incorrectly. If it used UTF-8 also, you wouldn't be running into these problems. ah ok, yeah it's the dreamhost default install (lol), i had a look and it doesn't define a character set to use, so must be defaulting to windwows-1252. thanks for all your help
|
# ? Aug 24, 2009 07:05 |