|
Shaocaholica posted:How do I use non scrolling output? For instance, if I want to draw a progress bar in the terminal? Is there something I should be using other than print and sys.stdout.write()? I typically do something like: code:
|
# ? Jul 6, 2010 05:38 |
|
|
# ? May 11, 2024 20:51 |
|
Thermopyle posted:The \r returns to the line beginning and the comma at the end suppresses the newline. That didn't work with python 3.1 in windows. Sorry if I didn't mention that before. I got a similar behavior with calling 'cls' and writing my own message but I'm not sure if this is a good way to do it. And it would obviously not work in a *nix OS.
|
# ? Jul 6, 2010 06:04 |
|
Ncurses?
|
# ? Jul 6, 2010 08:38 |
|
KARMA! posted:Ncurses? Not available for windows.
|
# ? Jul 6, 2010 08:53 |
|
Well, here's a new one. How can I get a list of partitions and their labels in windows? Not just drive letters but also their string labels. Edit: nm, found it: code:
Shaocaholica fucked around with this message at 09:49 on Jul 6, 2010 |
# ? Jul 6, 2010 09:42 |
|
Shaocaholica posted:That didn't work with python 3.1 in windows. Sorry if I didn't mention that before. I got a similar behavior with calling 'cls' and writing my own message but I'm not sure if this is a good way to do it. And it would obviously not work in a *nix OS. If by non scrolling, you mean not appending a newline to everything you call print on, print("foo", end="").
|
# ? Jul 6, 2010 09:49 |
|
b0lt posted:If by non scrolling, you mean not appending a newline to everything you call print on, print("foo", end=""). Note quite. I mean clearing the whole terminal between writes so you can animate a progress bar, etc. Most CLI encoding tools do this and so do most text based downloaders on *nix. Another tool that comes to mind is *nix 'top' which updates the whole terminal without appending.
|
# ? Jul 6, 2010 09:52 |
|
Shaocaholica posted:Not available for windows. wcurses
|
# ? Jul 6, 2010 13:38 |
|
Shaocaholica posted:How do I use non scrolling output? For instance, if I want to draw a progress bar in the terminal? Is there something I should be using other than print and sys.stdout.write()? http://code.activestate.com/recipes/576986-progress-bar-for-console-programs-as-iterator/
|
# ? Jul 6, 2010 14:32 |
|
Shaocaholica posted:That didn't work with python 3.1 in windows. Sorry if I didn't mention that before. I got a similar behavior with calling 'cls' and writing my own message but I'm not sure if this is a good way to do it. And it would obviously not work in a *nix OS. That's just because it's a python2 style print statement. Most people assume python 2 unless specifically told otherwise. Change it to something like print('%s\r' % i, end="") and it does work.
|
# ? Jul 6, 2010 15:28 |
|
Hughlander posted:http://code.activestate.com/recipes/576986-progress-bar-for-console-programs-as-iterator/ Ok, I got that working and it seems to do what I want but it only works if you only write one line.
|
# ? Jul 6, 2010 15:42 |
|
Shaocaholica posted:Ok, I got that working and it seems to do what I want but it only works if you only write one line. I understand your frustration with this. I first learned to program nearly two decades ago using QBasic, which had the awesome LOCATE statement which moved the cursor to any location on the text console. I wrote a whole text-based windowing system with that. Python's abilities in this area have left me wanting more.
|
# ? Jul 6, 2010 16:38 |
|
Sailor_Spoon posted:That's just because it's a python2 style print statement. Most people assume python 2 unless specifically told otherwise. print('%s' % i, end="\r") might be a little cleaner looking
|
# ? Jul 6, 2010 19:26 |
|
Thermopyle posted:I understand your frustration with this. I know exactly what you mean, and I believe that's what ncurses is for. The reason it's not as easy is that QBasic is built on DOS, which has a very simple terminal with fixed sizing. The modern terminal is much more complicated, and the common case it was designed for (stream IO) isn't really compatible with canvas-like operations. So you need a lot more software than just a locate() function to get it right...what happens when the user resizes the terminal? Anyway, in most cases, if you're writing a curses app, you're clearly doing something fairly complicated, so I'd consider decoupling the operation from the interface, like deluge does.
|
# ? Jul 6, 2010 20:52 |
|
sund posted:print('%s' % i, end="\r") might be a little cleaner looking print(i, end="\r") :P
|
# ? Jul 6, 2010 20:59 |
|
I am using myconnpy instead of the usual mysql db connector because I don't want to try to compile it on many different machines. The problem I am having is figuring out how to escape strings appropriately. I can't find an escape method on the db. Any idea how I can do it correctly? Thanks.
|
# ? Jul 7, 2010 16:02 |
|
sonic bed head posted:I am using myconnpy instead of the usual mysql db connector because I don't want to try to compile it on many different machines. The problem I am having is figuring out how to escape strings appropriately. I can't find an escape method on the db. Any idea how I can do it correctly? Thanks. Try oursql. It has real parameterization so you don't need to worry about that crap.
|
# ? Jul 7, 2010 16:55 |
|
MEAT TREAT posted:Try oursql. It has real parameterization so you don't need to worry about that crap. I'm trying to avoid using the compiled mysql libraries. Something written in native python would be the best.
|
# ? Jul 7, 2010 18:14 |
|
i've been doing some programming with pygame recently and since switching over to a mac (snow leopard) i have been getting 'no module named pygame' import errors. i'm using NetBeans 6.9 RC2 with Python 2.6.5 and pygame 1.9.1 i've tried re-installing both python and pygame but i really have no idea what i'm doing when it comes to configuring IDEs. how do i make NetBeans see pygame?
|
# ? Jul 9, 2010 01:07 |
|
clams posted:i've been doing some programming with pygame recently and since switching over to a mac (snow leopard) i have been getting 'no module named pygame' import errors. Is netbeans using your python 2.6.5 installation? I've heard it uses some internal jython compiler instead and thats probably the problem you're experiencing. See if you can find some option to specify which python its using.
|
# ? Jul 9, 2010 02:56 |
|
clams posted:i've been doing some programming with pygame recently and since switching over to a mac (snow leopard) i have been getting 'no module named pygame' import errors. Something is probably loving up your pythonpath. I had something similar happen recently; it turned out that a random .pth in my site-packages folder was redirecting an important part of my import namespace.
|
# ? Jul 9, 2010 02:57 |
|
Can someone show me where the documentation is that explains how this works:code:
|
# ? Jul 9, 2010 07:31 |
|
Shaocaholica posted:Can someone show me where the documentation is that explains how this works: This is probably what you want: http://docs.python.org/tutorial/datastructures.html#list-comprehensions
|
# ? Jul 9, 2010 07:40 |
|
Shaocaholica posted:Also, what other not common ways to do stuff are there with Python? I like that you can use conditionals in list comprehensions. code:
|
# ? Jul 9, 2010 19:46 |
|
Thermopyle posted:I like that you can use conditionals in list comprehensions. The ternary is also really useful in comprehensions: ['%d is even'%i if (i%2)==0 else '%d is odd'%i for i in xrange(20)]
|
# ? Jul 9, 2010 20:34 |
|
haha I never thought of that
|
# ? Jul 9, 2010 21:29 |
|
Shaocaholica posted:Can someone show me where the documentation is that explains how this works: I don't know if this is what you really meant to say, but list comprehensions are a common way to do things in python. They are generally preferred in many situations that would be done with map or filter in other languages.
|
# ? Jul 9, 2010 21:47 |
|
As part of my ongoing process to teach myself Python, I'm trying to write a small application that will take some user input and post it to twitter. I wrote a console version of the program that works great but I want to try and make a GUI version as well. Here is what I have so far (please keep in mind that I am extremely new to programming) code:
|
# ? Jul 10, 2010 02:22 |
|
Mr. Clark2 posted:As part of my ongoing process to teach myself Python, I'm trying to write a small application that will take some user input and post it to twitter. I wrote a console version of the program that works great but I want to try and make a GUI version as well. I'm not at all familiar with tkinter, so there may be other problems, but the one I can see is in your creation of the Button. You're passing the result of the function you mean to pass as the "command" argument, rather than the actual function. To do that, take away the brackets at the end. So, for instance, the first one should be code:
|
# ? Jul 10, 2010 02:41 |
|
Jonnty, thanks for the response. I tried what you suggested and then this error is generated when clicking on the Post button:code:
|
# ? Jul 10, 2010 15:45 |
|
Off the top of my head:code:
|
# ? Jul 10, 2010 16:01 |
|
Avenging Dentist posted:Off the top of my head: Both buttons work perfectly now, thanks! My book completely failed to mention the whole 'lambda' bit. If it's not too much trouble could you give me a brief explanation of that part?
|
# ? Jul 10, 2010 17:51 |
|
A = lambda: foo() is equivalent to def A(): foo() Basically a lambda is a way of defining a one-statement function inside of another expression. Generally when talking about lambdas people will also mention some stuff about closures, which I'm using. This isn't particular to the lambda syntax, since a regular function declaration (possibly inside of another function body) does this too. A closure pulls in the local variables you have and lets you reference them inside your inner function. If you want to know more, a search for "closure" will give you plenty of details.
|
# ? Jul 10, 2010 18:09 |
|
So apparently Numpy supports Python 2.x and 3.x with the same codebase now and will be released soon but is available in their SVN trunk now: http://www.mail-archive.com/numpy-discussion@scipy.org/msg26524.html
|
# ? Jul 11, 2010 01:50 |
|
No Safe Word posted:So apparently Numpy supports Python 2.x and 3.x with the same codebase now and will be released soon but is available in their SVN trunk now: gently caress yeah!!! About time.
|
# ? Jul 12, 2010 19:01 |
|
Avenging Dentist posted:A = lambda: foo() is equivalent to def A(): return foo() Fixed.
|
# ? Jul 13, 2010 06:27 |
|
Has anyone run into the following error while trying to compile a script using pyopengl and pygame with py2exe? Google has left this issue unresolved.code:
|
# ? Jul 13, 2010 12:29 |
|
How do I get pyQt running in windows? I've installed "PyQt-Py3.1-gpl-4.7.4-1.exe" and Python 3.1 but when I go to get SIP, all I get are sources. Am I supposed to get a prebuilt version for windows somewhere? Edit: oh wait, does PyQT only work with 32bit python? Edit2: WTF, according to this: http://images.autodesk.com/adsk/files/pyqtmaya2011.pdf I've got to build PyQt and SIP for 64bit windows and I also need a compiler installed (VS2008). I don't mind building stuff in other OSs but I've never not been able to find prebuilt binaries for windows. Shaocaholica fucked around with this message at 22:23 on Jul 14, 2010 |
# ? Jul 14, 2010 20:43 |
|
I'm trying to write a python script that takes 10 or so jumbled words as an input and checks them against a much bigger list of words in order to, uh, 'unjumble' it. my plan was basically this: the characters in every word in the main list are re-arranged alphabetically. The characters of the input words are also re-arranged alphabetically. This way the jumbled words can be matched up and then spit back out as a non-jumbled word. My problem is that I don't even know where to begin. So far I've basically figured out how to get python to retrieve a text file and list each word as a re-arranged jumble of characters arranged alphabetically. code:
code:
Kosani fucked around with this message at 01:35 on Jul 15, 2010 |
# ? Jul 15, 2010 01:32 |
|
|
# ? May 11, 2024 20:51 |
|
change that to print ''.join(sorted(line)) and you will get the strings you're looking for
|
# ? Jul 15, 2010 02:15 |