Re: curses and refreshing problem
Carl Banks wrote in news:69d2698a-6f44-4d85-adc3-1180ab158...@r15g2000prd.googlegroups.com: > Unless you are referring to some wget screen mode I don't know about, > I suspect wget outputs its progress bar using carriage returns > without newlines. If that's all you want, there is no need to use > curses. > > Here is a little example program to illustrate: > > import time, sys > for i in range(21): > sys.stdout.write('\rProgress: [' + '='*i + ' '*(20-i) + ']') > sys.stdout.flush() > time.sleep(1) > sys.stdout.write("\nFinised!\n") Thanks, that's it! I just assumed wget uses curses for the progress bar, so the carriage return didn't even cross my mind ;). -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
curses and refreshing problem
Hi, I'm trying to implement text output interface, something similar to wget, using curses module. There are just two things I can't find out how to do: prevent curses from clearing the terminal when starting my program, and leaving my output after the program closes. Any way to do this with curses? Thanks... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Bind compiled code to name?
"Martin v. Löwis" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > d = {} > exec source_code in d > some_name = d['some_name'] This works quite well! I can't believe after googling for half on hour I didn't notice this "exec ... in ..." syntax. One more thing though, is there a way to access "some_name" as a attribute, instead as a dictionary: some_name = d.some_name ? Thanks... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Bind compiled code to name?
If string `source_code` contains Python source code, how can I execute that code, and bind it to some name? I tried compiling with: code_object = compile(source_code, 'errorfile', 'exec') but then what to do with `code_object`? P.S. If my intentions aren't that clear, this is what I'm trying to do. I want to emulate this: import some_module as some_name but with my code in `some_module` string, and not in file. Thanks... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Can this be done with list comprehension?
Gary Herron <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > The problem is that list methods like insert do not return a list -- > they modify it in place. If you do > a = [1,2,3] > a.insert(0, 'something') > then a will have the results you expect, but if you do > b = a.insert(0,'something') > you will find b to be None (although a will have the expected list). I figured that out few minutes ago, such a newbie mistake :). The fix I came up with is: result = ['something'] + [someMethod(i) for i in some_list] Are there any other alternatives to this approach? -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Can this be done with list comprehension?
This is what I'm trying to do (create a list using list comprehesion, then insert new element at the beginning of that list): result = [someFunction(i) for i in some_list].insert(0, 'something') But instead of expected results, I get None as `result`. If instead of calling `insert` method I try to index the list like this: result = [someFunction(i) for i in some_list][0] It works as expected. Am I doing something wrong, or I can't call list methods when doing list comprehension? P.S. In case you're wondering, it has to be done in one line ;). -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning to 'try' block after catching an exception
Duncan Booth <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Catching only the specific exceptions you think you can handle would > be more Pythonic: that way things like sys.exit() will still work > inside some_function. I know, this was just a somewhat poorly example ;). > I prefer a 'for' loop rather than 'while' so I can limit the number of > retries. > > The following may or may not be 'more pythonic', but is something I've > used. It's a factory to generate decorators which will retry the > decorated function. You have to specify the maximum number of retries, > the exceptions which indicate that it is retryable, and an optional > filter function which can try to do fixups or just specify some > additional conditions to be tested. Interesting approach, I think I'll use something like that for avoding infinite loops. Thanks a lot... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning to 'try' block after catching an exception
alex23 <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > If you know what exception to expect, and you know how to "fix" the > cause, why not just put tests _before_ some_function() is called to > ensure that everything is as it needs to be? Because when you expect exception to occur on something like 0.01% of cases, and you have 4 or 5 exceptions and the code to test for each conditions that cause exceptions is quite long and burried deep inside some other code it's much better to do it this way ;). Too bad there's no syntactic sugar for doing this kind of try-except loop. -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning to 'try' block after catching an exception
André <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > How about something like the following (untested) > > done = False > while not done: > try: > some_function() > done = True > except: > some_function2() > some_function3() Sure, that works, but I was aiming for something more elegant and Pythonic ;). -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Returning to 'try' block after catching an exception
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ... # somehow goto 'try' block again In case it's not clear what I meant: after executing some_function() exception SomeExcpetion gets risen. Then, in except block I do something to fix whatever is causing the exception and then I would like to go back to try block, and execute some_function() again. Is that doable? Thanks. -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning values from function to Python shell/IPython
Jorge Vargas wrote: > well after all it's a function so the only ways you can get things out > of it are: > - return a dict with all the objects > - use global (very messy) > - use a decorator to do either of the above. Messy, all of those... :(. > on the other hand have you consider using a proper test package? > instead of inspecting the objects manually from the shell you could > make it all automatic. with assert statements. you could use the std. > python testing modules http://docs.python.org/lib/development.html or > something less verbosed like nose Usually, I'm using standard Python testing modules, but sometimes that is just an overkill. Sometimes I like to do 'exploratory programming', especially in the early phases of development - create a bunch of objects I want to play with and do that from IPython. Only way I found out to somewhat automate this procedure is to have a function that creates all of the test objects, and then raises an exception at the end. IPython starts ipdb, so I can work with the objects the function created (without copying them back to the shell). But this somehow looks too hack-ish for me, so I was wondering if there was an alternative... Anyway, thanks for your answer ;). -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Returning values from function to Python shell/IPython
Hi all! I have a runTest() function inside my module, which sets up and initializes lots of objects and performs some basic tests on them. Usually (from IPython) I just write `run my_module.py`, and then `runTest()`. But sometimes I would like to manually twiddle with objects runTest creates. Is there any way I can "return" all those objects local to runTest(), and have them available in IPython (or ordinary Python shell)? Thanks... P.S. I know I can do it from a: if __name__ == '__main__': # lots of object initialization... and then have all those objects available in the interpreter. -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Re: Order of evaluation in conditionals
Paul Hankin wrote: > Did you try to find the answer to your question in the python > reference manual? The relevant page is > http://docs.python.org/ref/Booleans.html Of course I first Googled (even Google Groups-ed) it, but I didn't notice that in the results. > To quote it: > The expression 'x and y' first evaluates x; if x is false, its value > is returned; otherwise, y is evaluated and the resulting value is > returned. Thanks (to both of you :>), that's it. -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Order of evaluation in conditionals
Hi all! Here is what's bugging me: let's say I have this code: if () and () and (): do_something() Is there a guarantee that Python will evaluate those conditions in order (1, 2, 3)? I know I can write that as a nested if, and avoid the problem altogether, but now I'm curious about this ;). Thanks... -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphical Engine
Vlad Dogaru wrote: > A few friends and myself were thinking of writing a graphical engine > based on OpenGL. Does Python have the required speed for that task? Are > there any examples out there of open-source engines which we can look > at? A Google search yielded no interesting results, but then again I'm > probably missing something. http://www.ogre3d.org/wiki/index.php/PyOgre -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping track of subclasses and instances?
Larry Bates wrote: > I'm not completely sure I understand the question but here goes. > Instances of > classes are classes can be stored in lists or dictionaries. In lists you > reference them via their index (or iterate over them) and in dictionaries > you can give them a name that is used as a key. I wish if it were that simple :). Here is a longer description - I have a function that given input creates a custom class and returns it back. The user is free to subclass that (even more, he should do that), and of course he will make instances of those subclasses. Now, my question is how to keep track of subclasses and their instances, without the need for user interaction (appending them to a list, or adding to dictionary)? Thanks, -- Karlo Lozovina - Mosor -- http://mail.python.org/mailman/listinfo/python-list
Keeping track of subclasses and instances?
Hi, what's the best way to keep track of user-made subclasses, and instances of those subclasses? I just need a pointer in a right direction... thanks. -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Dynamically creating class properties
Hi all, this is my problem: lets say I have a arbitrary long list of attributes that I want to attach to some class, for example: l = ['item1', 'item2', 'item3'] Using metaclasses I managed to create a class with those three attributes just fine. But now I need those attributes to be properties, so for example if 'A' is my constructed class, and 'a' an instance of that class: a = A() Now if I write: a.item1 = 'something' print a.item1 I want it to be actually: a.setitem1('something') print a.getitem1 Any idea how to do that with metaclasses and arbitrary long list of attributes? I just started working with them, and it's driving me nuts :). Thanks for the help, best regards. -- Karlo Lozovina -- Mosor -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic question
Cesar G. Miguel wrote: > - > L = [] > file = ['5,1378,1,9', '2,1,4,5'] > str='' > for item in file: >j=0 >while(j while(item[j] != ','): > str+=item[j] > j=j+1 >if(j>= len(item)): break > > if(str != ''): >L.append(float(str)) > str = '' > > j=j+1 > > print L > But I'm not sure this is an elegant pythonic way of coding :-) Example: In [21]: '5,1378,1,9'.split(',') Out[21]: ['5', '1378', '1', '9'] So, instead of doing that while-based traversal and parsing of `item`, just split it like above, and use a for loop on it. It's much more elegant and pythonic. HTH, Karlo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic subclassing ?
manatlan wrote: > I can't find the trick, but i'm pretty sure it's possible in an easy > way. It's somewhat easy, boot looks ugly to me. Maybe someone has a more elegant solution: In [6]: import new In [13]: class Button: : def buttonFunc(self): : pass In [14]: class ExtensionClass: : def extendedMethod(self): : pass In [15]: hybrid = new.instance(Button, Button.__dict__.update(ExtensionClass.__dict__)) In [17]: dir(hybrid) Out[17]: ['__doc__', '__module__', 'buttonFunc', 'extendedMethod'] Seems to do what you want it to do. HTH, Karlo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic question
Cesar G. Miguel wrote: > for j in range(10): > print j > if(True): >j=j+2 >print 'interno',j > > What happens is that "j=j+2" inside IF does not change the loop > counter ("j") as it would in C or Java, for example. > Am I missing something? If you want that kind of behaviour then use a `while` construct: j = 0 while j < 5: print j if True: j = j + 3 print '-- ', j If you use a for loop, for each pass through the foor loop Python assigns next item in sequence to the `j` variable. HTH, Karlo. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to copy a ClassObject?
Duncan Booth <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Consider yourself corrected. > > You could do what you are attempting with: > >tmp = new.classobj('tmp', First.__bases__, dict(First.__dict__)) > > which creates a new class named 'tmp' with the same base classes and > a copy of First's __dict__ except that the __name__ attribute for the > new class will be set to 'tmp'. The attribute values are still shared > between the classes (which is significant only if they are mutable), > but otherwise they won't be sharing state. > I have no idea why you would want to do this, nor even why you would > want a 'name' attribute when Python already gives you '__name__'. First of all, thanks for a clarification. 'name' attribute was just a (dumb) example, it was the first thing to come to mind. The idea behind all of this was to create classes dynamicaly, without knowing in advance their names, or base class(es). So I figured I'd just copy the base class and modify the attributes. Instead, this way of subclassing seems to work just right for my purposes. -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: How to copy a ClassObject?
Karlo Lozovina <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > how would one make a copy of a class object? Let's say I have: > class First: > name = 'First' > > And then I write: > tmp = First Silly me, posted a question without Googling first ;>. This seems to be the answer to my question: import new class First: name = 'First' tmp = new.classobj('tmp', (First,), {}) After this, tmp is a copy of First, and modifying tmp.name will not affect First.name. P.S. If my code is somehow mistaken and might not function properly in all cases, please correct me. Bye, klm. -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
How to copy a ClassObject?
Hi all, how would one make a copy of a class object? Let's say I have: class First: name = 'First' And then I write: tmp = First then 'tmp' becomes just a reference to First, so if I write tmp.name = "Tmp", there goes my First.name. So, how to make 'tmp' a copy of First, I tried using copy.copy and copy.deepcopy, but that doesn't work. P.S. Yes, I can do a: class tmp(First): pass but I'd rather make a copy than a subclass. Thanks. -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Tip: 'Open IPython here' in Windows context menu
Based on the idea from 'Open Command Window Here' utility from MS - add a context menu item, which allows you to open IPython in selected directory. ---cut-here--- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\ipython] @="IPython here" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\ipython\command] @="\"C:\\Program Files\\JPSoft\\TCMD8\\tcmd.exe\" /k cd %L & C:\\Python \\Scripts\\ipython.py" ---cut-here--- Save this as a "something.reg" file, doubleclick it and import into Windows registry. And that's it. While in Windows Explorer, right click any directory, and select "Ipython here" item... Btw, as you can see, I'm not using ordinary Windows cmd.exe, instead of it I use Take Command by JPsoft. If you want to use cmd.exe instead, just replace tcmd.exe path, with cmd.exes'. Hope this will be usefull to someone... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > It doesn't matter whether you have 0 or a million instances, > methods do not occupy more memory. That's what I was looking for! Thanks, to you and all the others. -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
What is more efficient?
Let's say I have a class with few string properties and few integers, and a lot of methods defined for that class. Now if I have hundreds of thousands (or even more) of instances of that class - is it more efficient to remove those methods and make them separate functions, or it doesn't matter? Thanks... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
SQLAlchemy, py2exe and Python 2.5 problem?
I've just upgraded to Python 2.5, SQLAlchemy 0.3.3, and py2exe 0.6.5 (the py2.5 version, yes). Simple: --- import sqlalchemy print 'Test' --- works when interpreted by Python, but when running it from compiled py2exe binary, it fails with this error: Traceback (most recent call last): File "main.py", line 1, in File "sqlalchemy\__init__.pyc", line 10, in File "sqlalchemy\orm\__init__.pyc", line 12, in File "sqlalchemy\orm\mapper.pyc", line 7, in File "sqlalchemy\logging.pyc", line 30, in ImportError: No module named logging Ofcourse, library.zip (in the dist directory) contains 'sqlalchemy \logging.pyc'. After I copy logging.pyc to library.zips' root, I get this error: Traceback (most recent call last): File "main.py", line 1, in File "sqlalchemy\__init__.pyc", line 10, in File "sqlalchemy\orm\__init__.pyc", line 12, in File "sqlalchemy\orm\mapper.pyc", line 7, in File "sqlalchemy\logging.pyc", line 30, in File "sqlalchemy\logging.pyc", line 33, in AttributeError: 'module' object has no attribute 'getLogger' Does anyone have a clue why this happens? And what is responsible for this? SQLAlchemy, or py2exe? Thanks in advance... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: wing ide vs. komodo?
"vj" <[EMAIL PROTECTED]> wrote in news:1162708898.962171.161120 @e3g2000cwe.googlegroups.com: > The embedded python shell is also a useful feature. Yes, but Debug Probe and Stack Data absolutely rock! Can't live without them anymore. Just set a breakpoint, run your code end then you can inspect all of the structures via Stack Data, and you can play with those structures using Debug Probe. Huge productivity boost... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Forum written in Python?
Are there any forum or bulletin board systems written entirely in Python? I got sick of PhpBB, mostly because I can't tweak and fiddle with the code, since I really don't like PHP and don't know it that well. I thought of writting my own simple forum software, but if there are existing projects out there, I wouldn't mind contributing. So far I found out about Pocoo, but it seems to immature right now, I was looking for something comparable to PhpBB or IPB? -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
SQLAlchemy and py2exe
I've installed SQLAlchemy under Windows (strangely, it didn't install inside ../site-packages/ as a directory, but rather as a SQLAlchemy-0.2.8-py2.4.egg file). I can import it with 'import sqlalchemy' and run my program with WingIDE, SPE and ofcourse in plain old Python shell (ipython actually). But when I build my .exe using py2exe and run the executable, it fails with 'Cannot import module sqlalchemy' error. Is it because SA is installed inside a .egg file, and can I somehow force it to install like all the other packages? Thanks guys... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
MP3 files and Python...
I'm looking for a Python lib which can read and _write_ ID3v1 and ID3v2 tags, and as well read as much as possible data from MP3 file (size, bitrate, samplerate, etc...). MP3 reproduction is of no importance... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Why aren't these more popular (Myghty & Pylons)?
I've been browsing what Python has to offer in the world of web programming for past few weeks, while preparing to select something for small, quick and dirty projects where my favorable solution, Zope3, is an overkill. There sure are handfull of solutions out there, but I didn't quite like any of them, starting from those with more of a framework approach (TG, Django, ...), and ending with really small ones, like Karrigell and Webpy. Ofourse, I haven't tested each and everyone, but I've read a lot of docs, and even more examples (Btw, those TG screencasts are really awesome for introduction), and found nothing that 'fits my brain' :). But, reading some old posts on c.l.py I found out about Myghty (http://www.myghty.org), and by reading the docs and examples, I came to like it. First of all, it's built with HTML::Mason as a role model, and although I haven't worked with Mason first hand, I heard about quite a few success stories. Besides that, the idea of components and MVC is also a plus in my book, API is quite clear and the documentation is really useful. It is hard to explain, but I fell in love at the first sight :). There's only one thing bothering me, and that is it's lack of publicity. There are only few posts on thig NG with some refference to Myghty, and even less when it comes to Pylons (http://pylonshq.com/), framework built on top of Myghy. Myghy project isn't that new to explain why people don't know about it, so is something fundamentaly wrong with it? Anyway, to make a long story short, those who haven't heard about it, be sure to check it out, you just might like it, but I would really like to hear from people (if there are such) using it in real world applications... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: print without newline "halts" program execution
Jay Parlar <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Your problem is that the 'print' statement is sending the text to > sys.stdout, and sys.stdout is buffered. I thought it was something like this, but I couldn't find it in the docs : (. > print 'Start: %f,'% st, > sys.stdout.flush() > sleep(10) > sp = time() > print 'Stop: %f, Duration: %f' % (sp, (st-sp)) This works excellent, *thank* you. > There are other ways to do this, but try this: And for purely academical purposes, what are those other ways to do it? I'm curious :). -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
print without newline "halts" program execution
Consider this short script: --- from time import time, sleep st = time() print 'Start: %f, ' % st, sleep(10) sp = time() print 'Stop: %f, Duration: %f' % (sp, (st - sp)) --- On my environment (Linux, py24), when run, Python first waits 10s, and then produces the entire output. How, can I make it print first part ('Start: %f, '), then wait 10s, and then append (WITHOUT NEWLINE) that second print statement? I'm writting a script with lot of output which has to go on the same line, but I don't want to wait for it to end to see output, I just want it to print parts as it's finished with them. Using sys.stdout.write() produces the same behavior, so what can I do? Thanks a lot in advance. -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Why optparse wont import?
Jorge Godoy <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Rename your file to something other than optparse.py... Oh my :(... I'm so ashamed :). -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Why optparse wont import?
If I create a file with only one line: --- from optparse import OptionParser --- I get this when I try to run it from "DOS" prompt: Traceback (most recent call last): File "optparse.py", line 1, in ? from optparse import OptionParser File "X:\data\other\source\python\population\optparse.py", line 1, in ? from optparse import OptionParser ImportError: cannot import name OptionParser When I try to do that from Python prompt everything works fine. What's the problem? -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code snippet?
Dave Hansen <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > In your code, I would simply remove the rn.seed() call. Regards, And that's what I'm gonna do :). The random part is not that important to my application so I wont investigate into further detail... anyway, thank you. -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code snippet?
Dave Hansen <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > I'm not sure what rn is, but it looks like a standard library > random.Random object. If so, I don't think you want to seed your PRNG > each time you use it -- your numbers might be much less random that > way. If it is the standard library object, the PRNG is seeded when > the module is first imported, so you may not need to seed it at all. Yes, it is random module. So, what is the preferred way of seeding random number generator? Just once in a file? Or something else? I just needed some "random" choices to be made, so I didn't dig much into random module. Anyway, thanks for pointing this out, appreciated. -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code snippet?
"Gerard Flanagan" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Class methods must have at least the 'self' argument. So Argh! :) Thanks guys! -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
What's wrong with this code snippet?
Here is it: --- class Human: def __init__(self, eye_one, eye_two): self.eye_one = eye_one self.eye_two = eye_two class Population: def __init__(self): self.house = [] for i in range(0, POPULATION_COUNT): self.house.append(Human(self.GenerateRandomColour(), self.GenerateRandomColour())) def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour --- Uppon running it gives this error: --- Initializing first generation population: Traceback (most recent call last): File "population.py", line 38, in ? earth = Population() File "population.py", line 26, in __init__ self.house.append(Human(self.GenerateRandomColour(), self.GenerateRandomColour())) TypeError: GenerateRandomColour() takes no arguments (1 given) --- If I remove GenerateRandomColour from class definition, and put it as a separate function, everything works fine. I've been staring at this code for half an hour and can't find what's wrong :(. Any help greatly appriciated :). -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Work with Windows workgroups under Python?
I'm running Python 2.4 under WinXP Pro, and I would like to do some basis operations on my LAN - get list of workgroups, list the computers in each workgroup and possibly connect to specific computer and get share/directory list? Is there some Pythonic way of doing this? Or any other less Pythonic way? Thanks... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: Flat file, Python accessible database?
[EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in news:[EMAIL PROTECTED]: > If you need it to be SQL-like, SQLite seems to be the right thing. Tried that one, but had some problems setting things up. On the other hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under Cygwin). The problem is, Pybsddb is as badly documented as Windows Registry, no examples, no tutorials, no nothing :(. Does anyone have some small (possibly documented) Python program which does some basic database routines - select, insert, and such? > It's not clear to me what you mean by "flat" file here, but if you mean > it should be human readable, maybe the csv module is the thing. > http://docs.python.org/lib/module-csv.html Well, no, that's not it, but anyway thnx for the link, I need to parse a lot of CSV files, so this will speed me up :). -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Flat file, Python accessible database?
I've been Googling around for _small_, flat file (no server processes), SQL-like database which can be easily access from Python. Speed and perforamnce are of no issue, most important is that all data is contained within single file and no server binary has to run in order to use the dbase. Oh, and I'm using Python under Cygwin. Ofcourse, ease of use and simplicity is most welcomed :). I'm currently playing around SQLite+PySQLite and BerkeleyDB, but those two seem like an overkill :(. Thanks in advance... -- ___ Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list