Python
Re: Python
I'm writing a simple comic book data thing using the Comic Vine API! It doesn't have much in the way of documentation or examples, just a big splat of structures that the API will return if you can figure out how to invoke it.
The Python side is easy as pants though. urllib.request and xml.etree.ElementTree are the cheatmodes as usual.
The Python side is easy as pants though. urllib.request and xml.etree.ElementTree are the cheatmodes as usual.
Re: Python
Woo! I now have a nice Qt program that can search the Comic Vine database for all comic volumes matching a query, download all the issue data for all comics within the volume, with release date and story arc data, and provide homogeneous filename suggestions based on its findings.
One Python idiom I'm getting a lot of use out of is the following:It seems to be the nicest way to detect problems where a function might return a useful value on success, return None on success but nothing was found, or throw an exception on misuse/file error/network error. Stuff like network connecting, file writing, dict inspection (especially with long paths on internal structure you know to there if the state is good).
I'm not particularly interested in what went wrong (or passing it up to the user interface), but I do want to handle problems to the extent where I can maintain good state. I'm unsure because it resembles amateurish Java 'I don't know how to deal with this exception so I'll just suppress it' coding.
Does anybody else use try-attempt-except-pass much?
I kind of miss Java's checked exceptions and javadoc. I can't find what kind of exception xml.etree.ElementTree.fromstring() might throw if I chuck it malformed XML.
Edit - Oh wait Python 3's docs mention it, Python 2's docs didn't.
One Python idiom I'm getting a lot of use out of is the following:
Code: Select all
def stuff(parameters):
...
result = None
try:
result = function_may_fail(a, b, c, d)
except IOError etc:
pass
if result:
process result object somehow
return some success object
else:
error stuff
(alternatively)
if not result:
abort returning appropriate failure number/object
good pathI'm not particularly interested in what went wrong (or passing it up to the user interface), but I do want to handle problems to the extent where I can maintain good state. I'm unsure because it resembles amateurish Java 'I don't know how to deal with this exception so I'll just suppress it' coding.
Does anybody else use try-attempt-except-pass much?
I kind of miss Java's checked exceptions and javadoc. I can't find what kind of exception xml.etree.ElementTree.fromstring() might throw if I chuck it malformed XML.
Edit - Oh wait Python 3's docs mention it, Python 2's docs didn't.
Re: Python
If anybody is into collecting digital comics, my comic renamer program is up at https://gitorious.org/comicrenamer-py
Probably more interesting as a tool to help folks learn Qt than do renaming though.
Probably more interesting as a tool to help folks learn Qt than do renaming though.
Re: Python
I wanted to know more about networky stuff, so I wrote myself a cheesy IRC client in Python.
Well, to be more specific, I just opened a socket to an ircd running on my laptop, and wired up some input and output text widgets to shove utf-8 chars to and from it. As long as you don't mind manually typing every part of the IRC protocol yourself, it's a fully functional (and compliant
) IRC client.
Well, to be more specific, I just opened a socket to an ircd running on my laptop, and wired up some input and output text widgets to shove utf-8 chars to and from it. As long as you don't mind manually typing every part of the IRC protocol yourself, it's a fully functional (and compliant
Re: Python
there are probably many python irc clients already, and libraries and that
Re: Python
No good, I doubt any of them are as bad as mine.
Re: Python
Woohoo! My python IRC thing is a go.
I got stuck for a few hours trying to make a dummy invisible Tkinter widget which would act as an intermediary between my IRC networking thread and the GUI mainloop thread. I wanted the IRC thread to be able to add items to a fifo queue of sanitized messages to handle and then send a 'notify' event that the GUI mainloop would respond to, eat up the messages and put 'em on screen/change GUI state.
You can't generate or respond to events that haven't been assigned geometry it seems. If I made a new Frame subclass with the main form as the master and tried to generate <<IRC>> events on it, nothing would happen. If I put the widget onto the form then it would work but that wasn't the model I wanted. Instead, I decided to put that responsibility onto the window itself so there are no extra invisible widgets sticking out.
I got stuck for a few hours trying to make a dummy invisible Tkinter widget which would act as an intermediary between my IRC networking thread and the GUI mainloop thread. I wanted the IRC thread to be able to add items to a fifo queue of sanitized messages to handle and then send a 'notify' event that the GUI mainloop would respond to, eat up the messages and put 'em on screen/change GUI state.
You can't generate or respond to events that haven't been assigned geometry it seems. If I made a new Frame subclass with the main form as the master and tried to generate <<IRC>> events on it, nothing would happen. If I put the widget onto the form then it would work but that wasn't the model I wanted. Instead, I decided to put that responsibility onto the window itself so there are no extra invisible widgets sticking out.
Re: Python
Just started looking at iPython and iPython Notebook
Early days but it looks kind of amazing
Early days but it looks kind of amazing
Re: Python
I've pretty much finishing up a web based reporting service I wrote in Python and JQuery for work. It isn't large, but has couple of dynamic report selection controls using ajax which was easy enough to implement, and then styled using CSS, though my styles tend to not to be the best, but it looks mostly the part and uses the following features:
* Easy config file, check, 40 lines of code!
* Full rollover Logging, check, 10 lines of code!
* Custom built web server with external/dynamic page loading, check, 300 lines of code!
* SQLite database build, select, update queries, check, 200 lines of code!
* Email HTML generation, check, 30 lines of code!
* Custom authentication, check, 50 lines of code!
* Other web pages + css + jquery 1000 lines of code.
A lot of the above is with the help of built in libraries, but its also down to the concise syntax and dynamic data structures that just get the job done. Dynamic lists, and dictionary lists make indexing data a breeze.
I think I'll be making Python my language of choice.
It use to be Java, but that has kind of gone the way of C++. Its just become bloatware with additional libs and syntax for Africa that can make it an unweilding mess. Also, the extra compile/link step and strong typing is starting to get in the way of 'just let me code!'.
* Easy config file, check, 40 lines of code!
* Full rollover Logging, check, 10 lines of code!
* Custom built web server with external/dynamic page loading, check, 300 lines of code!
* SQLite database build, select, update queries, check, 200 lines of code!
* Email HTML generation, check, 30 lines of code!
* Custom authentication, check, 50 lines of code!
* Other web pages + css + jquery 1000 lines of code.
A lot of the above is with the help of built in libraries, but its also down to the concise syntax and dynamic data structures that just get the job done. Dynamic lists, and dictionary lists make indexing data a breeze.
I think I'll be making Python my language of choice.
It use to be Java, but that has kind of gone the way of C++. Its just become bloatware with additional libs and syntax for Africa that can make it an unweilding mess. Also, the extra compile/link step and strong typing is starting to get in the way of 'just let me code!'.
- lazerwalker
- Baaaaa!

- Posts: 1319
- Joined: Wed Sep 03, 2003 10:22 pm 0
- Location: (Very) sarf of the river
Re: Python
iPython & the notebook are really good for maths & simulation. I'm in the process of slowly switching from Matlab/Octave for doing my calculations to Python & Numpy.gravy wrote:Just started looking at iPython and iPython Notebook
Early days but it looks kind of amazing
Re: Python
Realised that my IRC client in its current state is in effect a Python scriptable IRC chanbot. I went mad and wrote up a quick draughts AI routine and some REST-like interface overnight and now have a bot you can play draughts with over IRC.
Re: Python
Here's my client, fwiw. Not much to it!
It plays a mean game of checkers. Well, a game of checkers at least.
https://gitorious.org/python_irc/python_irc/
It plays a mean game of checkers. Well, a game of checkers at least.
https://gitorious.org/python_irc/python_irc/


