|
Centipeed posted:I am trying to wrap my head around how to make this more elegant. I can't think of anything: code:
code:
|
# ? Mar 9, 2009 16:53 |
|
|
# ? May 27, 2024 01:55 |
|
tripwire posted:I'm a little unclear about what you are asking, but if you are looking for a more idiomatic way of doing a 2d nested loop like that consider this instead: Perfect. Ever since I started using Python's self-iterating for loops I've wanted to avoid creating loop variables that I iterate myself. Also, the newline solution is great. I've run into another problem. What would make Python (Under Windows) instantly quit back to the command line without showing the compiler errors it produces? If I repeatedly run the code I can see flashes of a compiler error, but it instantly takes me back to the command prompt as if nothing had happened.
|
# ? Mar 9, 2009 17:32 |
|
I'm not too sure, maybe you could try running your script a line a time with pdb until you see whats being printed out. The documentation is here: http://docs.python.org/library/pdb.html
|
# ? Mar 9, 2009 17:48 |
|
tripwire posted:I'm not too sure, maybe you could try running your script a line a time with pdb until you see whats being printed out. The documentation is here: http://docs.python.org/library/pdb.html I've been trying that, but as soon as my program creates a new instance of Console, pdb stops doing anything. This console module will be the death of me, I'm sure.
|
# ? Mar 9, 2009 18:00 |
|
Centipeed posted:I've been trying that, but as soon as my program creates a new instance of Console, pdb stops doing anything. This console module will be the death of me, I'm sure. Yea, anything mucking with the terminal window's likely to mess you up. Maybe wrap your whole deal in a try/except and log to file? code:
|
# ? Mar 9, 2009 18:26 |
|
Maybe you could try something, which I normally wouldn't suggest, like this:code:
edit: Beaten. That's what I get for typing this while watching TV. Good point about ctrl+c, that extra clause gets rid of my concerns. Lonely Wolf fucked around with this message at 18:34 on Mar 9, 2009 |
# ? Mar 9, 2009 18:29 |
|
For those doing concurrency stuff I implemented futures in Python earlier today for those who may be interested: http://dpaste.com/11007/
|
# ? Mar 9, 2009 21:18 |
|
king_kilr posted:For those doing concurrency stuff I implemented futures in Python earlier today for those who may be interested: http://dpaste.com/11007/ I still think this is neat
|
# ? Mar 9, 2009 22:27 |
|
king_kilr posted:For those doing concurrency stuff I implemented futures in Python earlier today for those who may be interested: http://dpaste.com/11007/ So quick question on program flow here code:
edit: It's late and I'm tired... So in case my question doesn't make sense... Why isn't it written like this code:
ATLbeer fucked around with this message at 06:25 on Mar 10, 2009 |
# ? Mar 10, 2009 06:22 |
|
ATLbeer, Thread.run() returns a Future object (see line 44). This is an object that proxies the real value. I think line 43 should use "start" rather than "run" - run() just calls the handler synchronously.
|
# ? Mar 10, 2009 13:49 |
|
Pooball posted:ATLbeer, Thread.run() returns a Future object (see line 44). This is an object that proxies the real value. To expand on this(because this was my revelation into how to do this), in Python everything about an object is in it's attributes. What does it mean for an object to be an integer? It means it acts like a number, we can display it, we can add it to other numbers, etc. Well in Python all it means to display something is for it to have an __str__ method, or to add an __add__ method. All being an integer means is that it walks, talks, and quacks like one.
|
# ? Mar 10, 2009 19:53 |
|
I am quite new to programming with Python, and even more so with Qt, so I figure I should ask this question. I'm writing a program that scans a directory, and queries all of the folder names in that directory against IMDB (with imdbpy), stores the information in a sqlite database, and lets the user browse that database. Here's a screenshot, for example: All the functionality works, and the program is very fast - the problem is memory usage. For a database with 200 movies, the program uses about 120mb. I've narrowed down the problem: if I don't display the cover in the movie list, memory usage shoots down to about 40mb. For reference, the size of the folder that contains the cover images is 6mb. Here's how I'm currently implementing this: code:
code:
So, without berating me too badly, how can I improve this?
|
# ? Mar 12, 2009 03:49 |
|
real noob question here: I'm doing the exercises in "How to think like a computer scientist", and I'm stuck on one of the exercises for matrices. Here's what i have: [code] def add_column(matrix): """ >>> m = [[0, 0], [0, 0]] >>> add_column(m) [[0, 0, 0], [0, 0, 0]] >>> n = [[3, 2], [5, 1], [4, 7]] >>> add_column(n) [[3, 2, 0], [5, 1, 0], [4, 7, 0]] >>> n [[3, 2], [5, 1], [4, 7]] """ last_matrix = matrix[:] for index, list in enumerate(last_matrix): list[:len(list)] += [0] print last_matrix print matrix return last_matrix [code] there's also a doctest at the end. Basically it fails the last test, where I have to keep it a pure function. I thought I had done this by declaring last_matrix by splitting it. I've been loving around with this for like 3 hours now, could you guys help me out. The indents are all correct, i cant get it to translate with the BB code.
|
# ? Mar 13, 2009 02:30 |
|
bollig posted:last_matrix = matrix[:] code:
|
# ? Mar 13, 2009 02:48 |
|
ChiralCondensate posted:The copy-by-slice trick only copies the top list. You need to do a deep copy; copy.deepcopy will do it for you, or you can do it in the same go as your column-adding: From what I've gathered, the slice does work. The only problem is that it doesn't pass the last test. Which doesn't make sense to me. Also, I'm really trying to do this as explicitly as possible, and I don't really get what's going on with the .append deal. I could very well be mistaken, but the new_matrix prints out the same as the matrix, but has a different id, which to me means that the slice worked.
|
# ? Mar 13, 2009 03:20 |
|
the new matrix has a different id but check the ids of its elements vs the ids of the old matrix's elements to see what what was said.
|
# ? Mar 13, 2009 04:23 |
|
bollig posted:From what I've gathered, the slice does work. The only problem is that it doesn't pass the last test. Which doesn't make sense to me. Also, I'm really trying to do this as explicitly as possible, and I don't really get what's going on with the .append deal. I could very well be mistaken, but the new_matrix prints out the same as the matrix, but has a different id, which to me means that the slice worked. code:
|
# ? Mar 13, 2009 10:37 |
|
I'm trying to talk to an MS SQL database from python on a Linux box. I was using python-mssql which worked fine until the DB tried to return nVarChar (unicode) data, whereupon I saw this error:quote:internal error: SQL Server message 4004, severity 16, state 1, procedure uspWebPub_GetTrackingInfo, line 19: Anyway, anyone got any clues as to how to get unicode data out of MS SQL Server on a Linux box? EDIT: Found the solution, as usual immediately after posting, http://use.perl.org/~jdavidb/journal/37102. Perl to the rescue once again. Zombywuf fucked around with this message at 11:17 on Mar 13, 2009 |
# ? Mar 13, 2009 11:08 |
|
I used pyodbc last time instead of pymssql, with a little more success. http://code.google.com/p/pyodbc/ I dunno maybe there's still some working examples from the last time.
|
# ? Mar 13, 2009 12:24 |
|
ChiralCondensate posted:Yes, you do indeed have a new list object, but its elements (your row lists) are the exact same lists as the old: Aha, thanks. I got it now.
|
# ? Mar 13, 2009 13:23 |
|
tef posted:I used pyodbc last time instead of pymssql, with a little more success. I think that's more likely to work, I know the django-pyodbc guys prefer it to -mssql and django uses unicode everywhere so I'm sure it does as well.
|
# ? Mar 13, 2009 16:03 |
|
On the hunt for a Python package before I go reinvent the wheel I'm looking for a PubSub style messaging system that I can pass objects (like in Pyro) for the messages I basically have a process that is monitoring a data feed (IRC channel) and I need the resulting parsed data to be sent to any application that "subscribes" to the data feed. This data is real time data so a polling system is unusable and I'd like to be able to attach different applications to this data stream.
|
# ? Mar 13, 2009 16:05 |
|
ATLbeer posted:On the hunt for a Python package before I go reinvent the wheel This is similar to a JavaSpace/JMS (for Java) - Off the top of my head, does then Event server stuff in pyro get you close to what you want? http://pyro.sourceforge.net/manual/6-eventserver.html Otherwise, I got nothin - all the message-queue stuff out lately is cross language and polling based. I just had some thoughts about writing one in cython that just shot pickled objects around.
|
# ? Mar 13, 2009 16:23 |
|
m0nk3yz posted:This is similar to a JavaSpace/JMS (for Java) - Off the top of my head, does then Event server stuff in pyro get you close to what you want? http://pyro.sourceforge.net/manual/6-eventserver.html Eh... I haven't touched Java in years and wanted a pure Python solution. I have a bit more work on some other stuff. If there isn't anything out there I just write my own. Publishing pickled objects is basically what I'm looking for. Now that I read your link... I might play with that for a while this weekend
|
# ? Mar 13, 2009 17:07 |
|
ATLbeer posted:Eh... I haven't touched Java in years and wanted a pure Python solution. I have a bit more work on some other stuff. If there isn't anything out there I just write my own. Publishing pickled objects is basically what I'm looking for. Let me know if you want to put one together, I might be able to help out/contribute.
|
# ? Mar 13, 2009 17:11 |
|
ATLbeer posted:On the hunt for a Python package before I go reinvent the wheel Can't Twisted do something like this?
|
# ? Mar 13, 2009 22:59 |
|
Does it have to be in python? There are good messaging systems that python can use. For example: http://www.rabbitmq.com/
|
# ? Mar 14, 2009 00:19 |
|
king_kilr posted:For those doing concurrency stuff I implemented futures in Python earlier today for those who may be interested: http://dpaste.com/11007/ I have a question about the test() function: code:
|
# ? Mar 18, 2009 18:38 |
|
Kire posted:I have a question about the test() function: No, because with the def statement (wherever it's used, regardless of scope) the argument names aren't existing variables -- you're declaring them right there for reference inside the def block. Just think about it for a second it's defining a function, not calling it!
|
# ? Mar 18, 2009 18:58 |
|
I need to install wxPython on my winxp machine at work, but I cannot get administrative access which is required for the normal .exe installs. I thought wxPython would just be a package or module I could put into my Lib folder, but it looks more complicated than that. Or is it? Can I just pull all the .py files from the .tar and put them into the correct subdirectories, all of it inside /Lib? Will that let me import wxpython?
|
# ? Mar 20, 2009 20:43 |
|
Can anyone explain this?code:
code:
|
# ? Mar 21, 2009 01:17 |
|
Ooooor I should be using not x and not not(x)
tef fucked around with this message at 01:27 on Mar 21, 2009 |
# ? Mar 21, 2009 01:18 |
|
tef posted:Ooooor I should be using not x and not not(x) I wasn't aware not() was even valid syntax It's not listed as a builtin function; the grammar for it in http://docs.python.org/reference/expressions.html#boolean-operations doesn't mention any parentheses; but yet the paragraphs below the grammar in that link, describe 'not' as if it were a function. Oh god, it's even worse, you can do 1.and(2). What is this poo poo, Ruby? World turning upside down... VVVV I understand now, that makes a little sense. Still disturbed that I went so long not realizing how much one could twist Python's syntax bitprophet fucked around with this message at 22:32 on Mar 21, 2009 |
# ? Mar 21, 2009 14:30 |
|
not(x) is parsed as not (x) so 1.and(2) is 1.0 and (2)
|
# ? Mar 21, 2009 15:14 |
|
I'm working out of a python book that I burned about 75% of the way through, but I'm still feeling really, really hazy on some of the concepts and as many times as I've reread the big about classes my eyes still cross. I think I'd learn better from doing than reading, but powering through and moving on, trying to decipher the source code in this book it isn't getting any easier. Does anyone have a suggestion for a book/online tutorial about python's implementation of classes so I can try to get a better handle on this?
|
# ? Mar 22, 2009 06:20 |
|
fnordcircle posted:I'm working out of a python book that I burned about 75% of the way through, but I'm still feeling really, really hazy on some of the concepts and as many times as I've reread the big about classes my eyes still cross. I think I'd learn better from doing than reading, but powering through and moving on, trying to decipher the source code in this book it isn't getting any easier. checkout dive into python, it's a free online python book
|
# ? Mar 22, 2009 08:07 |
|
fnordcircle posted:I'm working out of a python book that I burned about 75% of the way through, but I'm still feeling really, really hazy on some of the concepts and as many times as I've reread the big about classes my eyes still cross. I think I'd learn better from doing than reading, but powering through and moving on, trying to decipher the source code in this book it isn't getting any easier. The official tutorial tends to be both more concise and more thorough than most Python books. http://docs.python.org/tutorial/classes.html Scaevolus fucked around with this message at 09:58 on Mar 22, 2009 |
# ? Mar 22, 2009 09:17 |
|
I'm using IDLE as my IDE, and I'm not sure if that is related to a problem I have with Tkinter. Any time I use self.quit to create a button which will "quit" the Tkinter window/program, it freezes. If I close Tkinter windows by clicking on the X in the top right they go away just fine, but I always have to force-quit a self-quitted application. What is going on? Also, is there any preference among you gurus between wxPython and Tkinter? (I can't use wxPython at work because I can't find a way to install the source files without needing admin rights on my winxp box.) Kire fucked around with this message at 20:15 on Mar 25, 2009 |
# ? Mar 25, 2009 20:02 |
|
For those who are interested in VM work or just want their Python faster this seems to be an intersting project: http://code.google.com/p/unladen-swallow/
|
# ? Mar 25, 2009 20:20 |
|
|
# ? May 27, 2024 01:55 |
|
king_kilr posted:For those who are interested in VM work or just want their Python faster this seems to be an intersting project: http://code.google.com/p/unladen-swallow/ Interesting? It's pure awesome and win. I spoked to a few people about it today, and it's very very real. I could see this supplanting CPython-trunk quickly should they hit the goals for this year.
|
# ? Mar 26, 2009 04:30 |