|
What's the current consensus on GUI frameworks and tools? I'm looking at sticking with wxPython (having written little more with it than a hello world app) but thought I'd check if there are any new killer tools before getting too invested.
|
# ? Dec 6, 2010 14:45 |
|
|
# ? May 9, 2024 17:41 |
|
I've used pyqt and the drag/drop gui builder they have seems to work as advertised, as far as I can see. I can't say I feel really strongly about it one way or the other though; and I haven't used wxwidgets to compare it against.
|
# ? Dec 6, 2010 15:42 |
|
I like PyQt for the same reason. Trying to specify your user interface with pure code is painful.
|
# ? Dec 6, 2010 16:19 |
|
Scaevolus posted:I like PyQt for the same reason. Trying to specify your user interface with pure code is painful. I've used WxPython and it was doable, but certainly not great for the layout of UI elements. It's pretty obvious about its C/C++ roots as well when it came to naming conventions/etc. No idea if any of the other toolkits/frameworks are better about that.
|
# ? Dec 6, 2010 16:56 |
|
Scaevolus posted:I like PyQt for the same reason. Trying to specify your user interface with pure code is painful. Yea, PyQt is the way to go. If you just want a single button or two, the new tkinter with themed widgets actually looks ok now, and is quick to write.
|
# ? Dec 6, 2010 17:51 |
|
tef posted:Use PEP8 This is super helpful, and I can't believe I glossed over it/missed it. thanks man, and thanks for the other tips. e: In regards to not worrying about OOP, in hindsight you're right. I'm happy I was able to write a working program that, if I read it a week ago, would have been gibberish. Cart doesn't go before horse. Thanks for pointing that out. UltraShame fucked around with this message at 20:17 on Dec 6, 2010 |
# ? Dec 6, 2010 19:42 |
|
Alright, giving PyQt a shot. A graphical layout editor will certainly be nice. The verbosity of doing really simple stuff manually was a real turn-off last time around. I guess the ease of using python for most other things has spoiled me a bit.
|
# ? Dec 6, 2010 19:49 |
|
UltraShame posted:This is super helpful, and I can't believe I glossed over it/missed it. basically, use as little complexity to solve your problem. sometimes oop can introduce more complexity than it removes. solving them in a more procedural way is a nice way to move onto oop. You can see your basic data type and the operations it supports. if you want to jam everything into objects you should use java there is an old saying 'debugging code is twice as hard as writing it, so if you write to the best of your ability you're no longer qualified to debug it'.
|
# ? Dec 6, 2010 21:24 |
|
tef posted:basically, use as little complexity to solve your problem. After I read the "you should use OOP" hint, I went and attempted to re-write the program that way, thinking I had done something fundamentally wrong. After a few minutes I just stopped and said "this is stupid, I already solved the problem." I figure when I run into a situation where OOP is truly appropriate, it'll be more obvious. Going to burn through Google's python lessons, and in the meantime, write some more increasingly complex programs. Thanks for taking the time to respond, tef.
|
# ? Dec 6, 2010 21:55 |
|
UltraShame posted:After I read the "you should use OOP" hint, I went and attempted to re-write the program that way, thinking I had done something fundamentally wrong. After a few minutes I just stopped and said "this is stupid, I already solved the problem." I figure when I run into a situation where OOP is truly appropriate, it'll be more obvious. The exercise is a simple one and there's not really much a reason to diverge from a simpler procedural approach for that sort of short script, but the exercise was probably also intended to get the programmer to approach the problem in an OOP fashion. In that example, note that you're applying various functions to the address book, so it could make sense to create an AddressBook class and transform those functions into its methods.
|
# ? Dec 6, 2010 22:43 |
|
I'm trying to optimise this code to compute the ego betweenness of nodes in a network (click here for source paper if you are interested: http://www.analytictech.com/borgatti/papers/egobet.pdf ). The following snippet is to calculate the paths of length two in the network.code:
You only need to calculate values when there is not a direct connection and you only need to calculate for half the "matrix" as links are assumed to be symmetrical. I am running python 2.5 though I have access to 2.6. The code works, but I need it to be as fast as possible, is there something I am missing? Maybe I could try to pre-calculate the elements in the matrix i need to check rather than looping?
|
# ? Dec 7, 2010 16:43 |
|
If you need it to be as fast as possible, why the gently caress are you writing it in Python? Write it in C, drop it into an extension module, then call it from your main library.
|
# ? Dec 7, 2010 17:24 |
|
So, I've got a file I need to parse some details out of. There are sets of results, separated by '--------------------', I need to parse each of these in order, is there any easy way to do this in Python? In Perl, all I had to do was change the separator variable $/ to whatever I needed, then do a standard for loop on the string containing them. Seems a bit odd if Python doesn't have a built in method or module available to simplify this.
|
# ? Dec 7, 2010 18:51 |
|
Rohaq posted:So, I've got a file I need to parse some details out of. str.split('--------------------')
|
# ? Dec 7, 2010 18:54 |
|
Thermopyle posted:str.split('--------------------') Here's a Perl example: code:
|
# ? Dec 8, 2010 03:42 |
|
While translating from one language to another is rarely a 1:1 affair, I will say that the Perl you're translating from has a few superfluous elements and a few headscratch-inducing statements. I'm also curious if the output is intended to be double-spaced. Nb. that your [mis]statement that you were looping over the "string containing them" is probably what caused Thermopyle to think you had the whole thing slurped into memory such that a split() would be appropriate.
|
# ? Dec 8, 2010 04:03 |
|
well, to make it sane, if you restrict your marker to something that's on it's own line (which is a fair assumption) then there's this:code:
pre:here's your stuff: "[], ['what\\n'], ['up\\n', 'in\\n'], ['this thread\\n'], ['1\\n', '2\\n', '3\\n', 'for real?\\n']" pre:more test_txt -------------------- what -------------------- up in -------------------- this thread -------------------- 1 2 3 for real? -------------------- (if you don't want the trailing \n, slice the line as you append it)
|
# ? Dec 8, 2010 06:25 |
|
Please critique my first Python "library", which I forked from some other guy and "improved": https://github.com/praxxis/turbine One thing that bugs me is documentation. I'm used to PHPDoc, which has a pretty simple syntax IMO - from what I've seen of Python class documentation, its all reStructured text, which I find kinda... loose? I like putting in my @param's and whatnot, but I cant see if there's a "standard" way of documenting in Python. What does everyone else do for documentation?
|
# ? Dec 8, 2010 11:22 |
|
Otto: The only programming experience I have beyond GWBASIC and dabbling is when I worked on a job in a small business where the technical guy quit, so he showed me how to keep the ugliest records system ever (computers and manila folders notwithstanding) running with his perl stuff and change and add to it in the most rudimentary way possible. I should have explained that. regexps made sense to me, perl itself kind of didn't. After reading again through 'A Byte of Python', it really made me pick up quite a few badHabits. quote:One thing that bugs me is documentation. quote:Please critique my first Python "library", which I forked from some other guy and "improved":
|
# ? Dec 8, 2010 13:43 |
|
PraxxisParadoX posted:One thing that bugs me is documentation. I'm used to PHPDoc, which has a pretty simple syntax IMO - from what I've seen of Python class documentation, its all reStructured text, which I find kinda... loose? I like putting in my @param's and whatnot, but I cant see if there's a "standard" way of documenting in Python. What does everyone else do for documentation? Sounds like you're describing epydoc's fields. The only real 'standard' in python I know of is use docstrings instead of comment blocks, and make sure it generates a nice helpful html version.
|
# ? Dec 8, 2010 16:00 |
|
Otto Skorzeny posted:While translating from one language to another is rarely a 1:1 affair, I will say that the Perl you're translating from has a few superfluous elements and a few headscratch-inducing statements. I'm also curious if the output is intended to be double-spaced. That was purely an example to show what I meant; I altered the termination point so that it would load everything between two sets of dashes. In my actual script, I'm likely going to use regular expressions to parse information out of each record. I don't want to load it all into memory, and then split it, because I may be working with large files. Lurchington posted:well, to make it sane, if you restrict your marker to something that's on it's own line (which is a fair assumption) then there's this:
|
# ? Dec 8, 2010 16:02 |
|
PraxxisParadoX posted:Please critique my first Python "library", which I forked from some other guy and "improved": https://github.com/praxxis/turbine I'm a big fan of Sphinx. It does a decent job of scanning modules and picking up certain details. It's meant more as a separate documentation system, but once you get it set up to your liking it produces a number of formats really quickly. Edit: And it may be pedantic, but I personally wouldn't have gone with the "_coerce_list" method. I would have just done the following: code:
Captain Capacitor fucked around with this message at 17:43 on Dec 8, 2010 |
# ? Dec 8, 2010 17:39 |
|
Captain Capacitor posted:I'm a big fan of Sphinx. It does a decent job of scanning modules and picking up certain details. It's meant more as a separate documentation system, but once you get it set up to your liking it produces a number of formats really quickly. Captain Capacitor posted:Edit: code:
|
# ? Dec 9, 2010 08:04 |
|
Why not just use append? >>> usernames = [] >>> usernames.append("praxxis") >>> usernames ['praxxis'] >>>
|
# ? Dec 9, 2010 08:13 |
|
Ok, I'll stop my programming 101 poo poo, resume your productive discussion. Sorry, fellas.
|
# ? Dec 9, 2010 10:19 |
|
leterip posted:Why not just use append? Would you believe that such a simple solution never occurred to me. Well played
|
# ? Dec 9, 2010 11:23 |
|
A while ago a coworker of mine mentioned that the PEP-8 requirement to keep your code under 79 characters wide was made obsolete by a later PEP which increases the limit to 120 characters. I have searched and searched but can not find this magical newer line-extending PEP. Does anybody know what my coworker may be thinking about?
|
# ? Dec 12, 2010 22:46 |
|
nbv4 posted:A while ago a coworker of mine mentioned that the PEP-8 requirement to keep your code under 79 characters wide was made obsolete by a later PEP which increases the limit to 120 characters. I have searched and searched but can not find this magical newer line-extending PEP. Does anybody know what my coworker may be thinking about? Cocaine.
|
# ? Dec 13, 2010 00:57 |
|
king_kilr posted:Cocaine. Figured as much. Anyways, I have another question. I have a module that looks like this: code:
|
# ? Dec 13, 2010 17:37 |
|
nbv4 posted:Figured as much. from .exceptions import MyException
|
# ? Dec 13, 2010 18:20 |
|
Janin posted:from .exceptions import MyException ValueError: Attempted relative import in non-package
|
# ? Dec 13, 2010 19:14 |
|
Which version of python is this? I think there were some relevant changes between versions you could also try: from module_name.exceptions import MyException this is the kind of thing that always bugs me though, so, meh.
|
# ? Dec 13, 2010 19:33 |
|
nbv4 posted:ValueError: Attempted relative import in non-package The correct way to handle imports is either absolute (import module_name.some_file) or relative (import .some_file , import ..other_module.foo). Relying on old behavior like semi-absolute imports will cause unpredictable failures during imports. in some_file, do something like this to see how it's being imported: code:
|
# ? Dec 13, 2010 19:39 |
|
Yet another 'critique my code' post. I needed to read a file backwards for some reason and mashed some horrible script out of Google snippets, so I figured it would be a nice exercise to make it look nice(r). http://pastebin.com/npK2YzDc The main questions are asked in inline comments, but I'm looking at overall Pythonicity, as well.
|
# ? Dec 13, 2010 23:17 |
|
Munkeymon posted:Yet another 'critique my code' post. I needed to read a file backwards for some reason and mashed some horrible script out of Google snippets, so I figured it would be a nice exercise to make it look nice(r). code:
code:
code:
code:
code:
code:
I'll play with the meat of the function a little more, it does feel like there should be a better way, but I don't really do a whole lot of file handling.
|
# ? Dec 14, 2010 00:14 |
|
Sailor_Spoon posted:the file will get closed when it goes out of scope
|
# ? Dec 14, 2010 02:39 |
|
Closing the file with either a with statement or a try-finally is usually better. itertools.islice(open('your_file', 'rb'), -1, 0, -1) Just kidding. It'd be neat though
|
# ? Dec 14, 2010 06:10 |
|
Lurchington posted:Closing the file with either a with statement or a try-finally is usually better. Yeah, don't think I didn't check itertools first. Sailor_Spoon posted:stuff It started life as a class before I realized I could just write a generator and skip all the manual state management bullshit, thus TheName. Also, I should have mentioned it was supposed to be used like a module, so that's why I did my importing inside the function - I guess I'll move that to an __init__ block? Edit: hmm, looks like I was misunderstanding the format requirements of a module - this is easier than I thought Sailor_Spoon posted:Type checking is usually the wrong way to do things. Here, I would probably do something like ... and let either file mode errors or IOErrors bubble up Wouldn't that be a lot less useful to an end user? Consider what happens when the user (hopefully accidentally) passes in a file that happens to not be seekable: "Why is that stupid module trying to call open on the file I sent in?!" Then they have to read and understand the code to know why something is failing. Munkeymon fucked around with this message at 17:57 on Dec 14, 2010 |
# ? Dec 14, 2010 16:26 |
|
Munkeymon posted:Wouldn't that be a lot less useful to an end user? Consider what happens when the user (hopefully accidentally) passes in a file that happens to not be seekable: "Why is that stupid module trying to call open on the file I sent in?!" Then they have to read and understand the code to know why something is failing. Depends on your user, I guess. I'd much rather get an error then have the function return None, which could mean a lot of things. Also, does a file that's not seekable still have the seek method? I assumed it does, so an error on seek would presumably not get caught by that except.
|
# ? Dec 14, 2010 18:53 |
|
|
# ? May 9, 2024 17:41 |
|
code:
|
# ? Dec 14, 2010 19:57 |