|
I'm trying to write some function to upload files via FTP. My "problem" is that it feels like I'm kludging my status updates with percent done, KB's uploaded, and KB per second. The reason I've done it as I've done it is that I can't think of a better way to pass data back and forth between each time the callback is called. In short, I hate screwing with global variables like this, is there a better way? code:
|
# ¿ Jan 20, 2009 19:21 |
|
|
# ¿ Apr 27, 2024 13:34 |
|
Two related questions: 1. Can someone please compile MySQLdb for Python 2.6 on Windows? On sourceforge a couple of random people have attempted it, but neither of their packages work for me: code:
Thermopyle fucked around with this message at 20:03 on Mar 1, 2009 |
# ¿ Mar 1, 2009 19:30 |
|
Janin posted:Despite all the hype pip receives, it fails to perform the two tasks I need a package manager to do. If all I had to worry about was pure-python tarballs installed on POSIX systems, there would be no need for any tool but "cp". Yes, I really wanted to use pip, but the lack of Windows support turned me off. I wish it supported Windows not only for my current projects, but I want pip to spread far and wide, and not supporting Windows will hinder that.
|
# ¿ Mar 7, 2009 05:09 |
|
Funnehman posted:I started learning python yesterday, and bumped in to some pretty expansive python IRC bot guides on http://www.devshed.com and had tons of fun with that all day. Only problem now is, I don't know what I want to(or what I'd even be capable of) outside of that. Lots of people say that's the hardest part of learning to program, which sucks because when I'm trying to make stuff and have ideas I'm having a blast, but after screwing around making various IRC bots to do different things all day I don't know where to go next.. This is probably a really stupid question, but does anybody have maybe a suggestion or two on fairly beginner friendly projects to work on? When I started learning python 6 months ago, I used it to solve little problems that I run in to every day. For example, I had a directory with 10,000+ images that I wanted to sort in to different directories by resolution, so I wrote a script to do that. Another thing was that I wanted to graph the different stats reported by my cable modem's web interface, so I wrote a python script to fetch that stuff into a csv every five minutes. Basically, think about things you do every day and figure out if there's a way to write a script to do it better.
|
# ¿ May 2, 2009 18:51 |
|
Funnehman posted:Yeah I have a few things like that, I do wish I had more though, I just can't wrap my head around OOP and poo poo, up until an hour or two ago, I had no clue how to call the functions in module files, and poo poo like that. Actually, I'm kind of in the same boat. I'll learn something only if I have a reason to, and I haven't really had a reason to use classes or any OOP stuff. I haven't really done anything where I could see a reason to use anything other than regular ole' functions. I have wrote a little something that I've released into the wild, though! I've got to do a little hacking on it, because I didn't realize at the time that python now includes the json module... Thermopyle fucked around with this message at 22:12 on May 2, 2009 |
# ¿ May 2, 2009 22:10 |
|
Sylink posted:Can someone explain parsing with elementtree to me, it makes no sense and the effbot stuff seems to all be about making xml, I just want to get information. I have no experience with elementtree, but you may want to look at BeautifulSoup.
|
# ¿ May 9, 2009 16:29 |
|
I'm kind of a beginner, and this is my story. I don't get classes. Every time I start a project I think: "Damnit, I'm going to learn what these are good for now." Except, once I start, I end up not using them because I'm comfortable with the way I do things. Basically I worked all the way through Think Python up to the Files chapter. When I got to "Classes and objects" I started reading and then thought "I don't need this poo poo." and then went out and wrote a bunch of scripts. I want to learn them, but similar to how many people need a project to learn to program, I need a reason to use them before I'll learn them. Basically, I want someone to talk me into thinking they're useful for something. Thermopyle fucked around with this message at 16:33 on May 25, 2009 |
# ¿ May 25, 2009 15:54 |
|
jupo posted:From what you've said it's safe to assume that the kind of things you're programming are fairly small in scale. For simple scripts that are smaller than a few hundred lines of code the benefits of classes really aren't obvious. Once you start getting into some more meatier projects the benefits classes will provide in structuring your data in a modular way will become much more apparent. This is true. Largest of my scripts are around 150 lines. Most of them are automation scripts like scraping something from a website and doing something with that, or organizing files, etc... I guess I'll have to think of a "meatier" projects.
|
# ¿ May 26, 2009 00:48 |
|
Mechanize is giving me fits. Basically, it doesn't recognize that there are any forms on this page. Here's some demonstration code: code:
code:
Other Browser methods will follow links on that page, but forms just won't work. I can get forms on other sites to work fine. I'm trying to write a script that will invite to our Steam Group anyone who ranks above a certain rank on our Psychostats. This requires logging in and maintaining cookies and whatnot...thus the use of mechanize.
|
# ¿ May 29, 2009 21:01 |
|
Sailor_Spoon posted:I ran it on OSX, python2.6, mechanize 0.1.11 and got some weird poo poo. I just called br.open(), and then br.forms() and got: This is odd. I get the same errors I mention in my post on linux with python 2.5 and windows with python 2.6. Twill also gives me the same errors. Guess I'll dig in to it more.
|
# ¿ May 31, 2009 01:56 |
|
Centipeed posted:What is the "accepted" way of implementing a simple substring search for plain text? Is there something wrong with str.find()?
|
# ¿ May 31, 2009 22:00 |
|
bitprophet posted:To ask a Python question: anyone know of any decent "CLI UI" (and not curses-based, I don't think) libraries for Python? I'm thinking of commonish stuff like progress bars, spinners, formatting data into columns, simple "choose option A B or C" menus, and so forth. (I could swear I saw a PyMOTW posting on that last one, but can't find it now. Maybe I should ask Doug...) If this exists, it would be cool. I'm always writing progress bars and the like.
|
# ¿ Jun 22, 2009 01:05 |
|
His Neutralness posted:How would I keep printing on the same line (just using the shell), like if I was printing the speed something was downloading at? code:
|
# ¿ Jun 30, 2009 19:39 |
|
Ok, I've decided to just make myself learn wtf classes are good for. I'm designing a script to take entries from my google reader shared items rss feed and do various things with each item like post it to a Twitter feed, Facebook, post it on a forum, etc... The problem is that classes seem kind of weird to me, and I'm having a hard time thinking about them with the right mind-set. This is my current thinking about some classes to use:
The second item I'm a little confused about. On the one hand it seems like I should make it a class because classes are cool, but on the other hand, I don't really see a reason for it to be a class as the things it does should only be done once each time my script is run. Basically, I'm just looking for some ideas and thoughts about how people with experience would design such a project.
|
# ¿ Aug 3, 2009 17:54 |
|
acker posted:Why not just have a function that takes the URL and returns a list of instances of the item class? Basically because I'm a noob to OOP and didn't know if it was bad form to mix functions and classes in such a manner. Of course, now that I think about it, I use regular Python objects all the time...
|
# ¿ Aug 3, 2009 18:51 |
|
Mata posted:I feel really stupid but I'm not really used to this language... how do you change parts of a string? Strings in python are immutable. The best you can do is create a new string that is a variation on the original. Maybe something like this: code:
|
# ¿ Aug 9, 2009 15:15 |
|
TheMaskedUgly posted:I'm new to python, but I've written a long program and it has an issue. Not enough info. Post the code. Also, a couple of hundred lines isn't long at all, so don't worry about that.
|
# ¿ Aug 12, 2009 00:04 |
|
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 |
|
Ethereal posted:Does anyone have recommendations for a good host with Python as a usable language? I'm planning on setting up a small-ish site and don't need that much bandwidth per month, just a good reliable provider. I've had plenty of success with Dreamhost.
|
# ¿ Aug 28, 2009 00:38 |
|
As a fairly novice programmer who's beginning to write more complex pieces of code, I'd like more advanced programmers to look at my code and tell me how badly I've hosed up. I've currently got a class I'm writing that takes a filename of a downloaded TV show and tries to parse out the episode and season number. It's about 100 lines long so far. Is there a good site out there focusing on hooking up programmers who are willing to look at other people's code? Would someone here like to look at it and make some comments for me? edit: Hell, i'll throw it up on pastebin and if someone wants to look they can just do it.... http://pastebin.com/ma24c43 sample use: code:
Thermopyle fucked around with this message at 22:13 on Sep 7, 2009 |
# ¿ Sep 7, 2009 22:06 |
|
outlier posted:Woah. Thank you! Exactly the sort of information I was hoping for. tef posted:That and there is almost no reason to make it a class over a function that returns a string You know, I started to write a function and then I decided I'm going to stop dicking around and make myself learn how the hell classes work. Besides, in the future I may expand this into a more full-featured program where I'd like to be able to query each bit of info. I was under the impression that a class would would facilitate that better. Lurchington posted:I've been fooling around with TV Show name parsing for a LONG time, and depending on how much you delve into it, you can see all my work at Keasby's google code repo. Thanks, I'll look it over.
|
# ¿ Sep 9, 2009 18:56 |
|
RobotEmpire posted:1. Should I just give up and install a Linux flavor if I really want to get back into teaching myself Python? (And how to code, in general) 1. Python is great on Windows. 3. I decided to learn Python this summer. I'm 31, and while I'm no elite hacker dood, I haven't had any problems.
|
# ¿ Sep 13, 2009 00:07 |
|
Janin posted:And here's the biggest, worst problem: for 99% of Twisted, the documentation is insufficent to know in what ways the various procedures are manipulating the implicit, global, god-state. You're going to spend more time reading the Twisted codebase than your own code, because every abstraction they've implemented leaks like hell. I wanted to use Twisted awhile back for some project. I'm pretty new to this whole programming thing, and after futzing around for a few hours I just gave up on Twisted because of the god-awful docs. So yea, Twisted documentation is pretty crappy.
|
# ¿ Sep 14, 2009 23:14 |
|
I'm writing some stuff that interacts with utorrent via it's Web API. One of the things I do is create a dictionary of utorrent settings like this: code:
code:
code:
|
# ¿ Sep 24, 2009 21:42 |
|
ErIog posted:Why don't you have your change_setting function submit the change, and then modify the dict with that information? I mean, if you're changing the setting yourself, then you're going to want your dict to keep track of it. Yeah, this is actually what I do now. It just seems like it would be more...I dont know..."objecty" and elegant if by modifying the dict I was actually modifying the setting. This was more idle thought than something I've got to do... jupo posted:You can subclass dict and override its __setitem__ method that gets called every time you add/update a keyvalue pair: oooo. I get it, thanks!
|
# ¿ Sep 24, 2009 22:09 |
|
Ok, completely different question... I'm starting on my first projects that I think will benefit from splitting into more than one file. To start out with I'm taking a long-ish script I wrote and dividing it into several files. What's the best way to handle utility functions that are used both in my main file and in the modules that I import?
|
# ¿ Sep 24, 2009 22:51 |
|
From the python docs:code:
|
# ¿ Oct 20, 2009 16:42 |
|
Milde posted:Error doesn't have any attributes or methods but it does inherit all of the attributes and methods from the Exception class. The other two classes have their own __init__ methods because they apparently need to deviate from their base classes. Right, but I mean why create the Error class at all? Why not just have the InputError and TransitionError inherit directly from Exception?
|
# ¿ Oct 21, 2009 02:42 |
|
BeefofAges posted:What would you do when you decide that all of your errors should have some common property? Would you go and edit each one individually? I thought of that, but if that was the point of the example, it seems like the docs should havve actually included a common property instead of "pass". So I assumed that wasn't the point.
|
# ¿ Oct 21, 2009 17:17 |
|
Objects with attributes composed of standard data types along with attributes that are other objects, how do I handle persistent storage?
|
# ¿ Oct 24, 2009 18:52 |
|
code:
|
# ¿ Oct 24, 2009 21:25 |
|
Habnabit posted:So I've long been sick of MySQLdb for being a horrible mysql driver as well as just being horribly written in general. Of course, there's also frequent questions on #python regarding either how horrible MySQLdb is or why the maintainer hasn't released any 2.6 binary packages for windows. Good for you! Awhile back I almost got to the point where I was going to teach myself how to do the same. Instead, I figured out how to compile MySQLdb for Windows myself (get it here if anyone needs it). I'll be keeping an eye on your project, though.
|
# ¿ Oct 31, 2009 18:21 |
|
Thought I'd post this here as esr wrote ForgePlucker in python. He's had a couple blog posts about the wisdom of scraping HTML with regex, and as always, the posts and the comments are entertaining. http://esr.ibiblio.org/?p=1411
|
# ¿ Nov 17, 2009 18:52 |
|
What's the right way to debug a function? Specifically, I'm working on a script right now with a function that's giving me some problems. When it drops back to the interactive interpreter I'd like to explore the values of various variables that are local to the function, but we're not in the function anymore so those variables aren't accessible. code:
|
# ¿ Nov 18, 2009 23:25 |
|
Which is better?code:
code:
|
# ¿ Nov 28, 2009 19:18 |
|
tehk posted:It depends on what shelf is, and how you are using it. If save is not manipulating its own object I would not make it a method of obj, however if it is some object relational thing then the second approach makes sense. You have a third option of adding save to a subclass of what ever type(dict) shelf is. That seems the least magical for when you are reading the code later. Shelf is a shelve. I'm storing my object on disk. Save isn't manipulating it's own object per se...it's storing the object in the shelve.
|
# ¿ Nov 28, 2009 22:12 |
|
HatfulOfHollow posted:I'm confused why you would want to store the object in the shelf. It really doesn't make much sense to me. That's how the shelve module works. quote:A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings. The question boils down to: Is it better to have a function insert an object into a shelf, or is it better to have an object put itself (via a method) on the shelf? Thermopyle fucked around with this message at 23:57 on Nov 28, 2009 |
# ¿ Nov 28, 2009 23:53 |
|
HatfulOfHollow posted:No I mean, why do you need a save method? Why can't you just do It seems like it's the most maintainable. Say I want to switch to MySQL, or some fancy other method of persistence in the future.
|
# ¿ Nov 29, 2009 18:56 |
|
Plorkyeran posted:Then you'll have to change __setitem__ instead of save. Isn't it as wide as it is tall? I mean, the dict-like nature seen in "save" is just an artifact of using shelve. Forget about shelve. Pretend the contents of "save" is code for writing results to a MySQL database. The question is more about coding style and less about shelve.
|
# ¿ Nov 29, 2009 20:29 |
|
|
# ¿ Apr 27, 2024 13:34 |
|
Plorkyeran posted:The class obj(): def save(self): shelf[self.name] = self version actually does do something interesting, as it gives objects control over how they're persisted. However, if def save(obj): shelf[obj.name] = obj was ever actually useful, then it should actually be class obj(): def save(self): save(self.name, self), as having to modify every class that can be persisted when you change persistence layers is almost as bad as having to change every place where an object is saved. In Stack Overflow style, I mark this as the accepted answer.
|
# ¿ Nov 29, 2009 21:44 |