Beta 0.21 of MMA - Musical MIDI Accompaniment
Beta 0.21 of MMA - Musical MIDI Accompaniment - is now available for downloading. Included in this release: Minor bug fixes, MAJOR change to the modules filename and import routines (shout if broken), MidiInc fixes, MidiInc lyrics import. Yet again, this may be the last BETA!!! MMA is a accompaniment generator -- it creates midi tracks for a soloist to perform with. User supplied files contain pattern selections, chords, and MMA directives. For full details please visit: http://users.xplornet.com/~bvdp/mma/ If you have any questions or comments, please send them to: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
how to print without blank?
I want to print 3 numbers without blank. for x in range(3): ... print x ... 0 1 2 for x in range(3): ... print x, ... 0 1 2 how to print 012 ? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Mysterious EOFError
Hi, I'm executing a python script as a cron job. When I run it myself from the command line it works, but when cron executes it I get an EOFError: File /home/rex/cronscript.py, line 6, in ? level = int(raw_input(hello?)) EOFError: EOF when reading a line It's not the last line of the file. When I run it as root from the command line I don't get any errors. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to print without blank?
Ju Hui wrote: I want to print 3 numbers without blank. for x in range(3): ... print x ... 0 1 2 for x in range(3): ... print x, ... 0 1 2 how to print 012 ? thanks. You may want to use the write command with stdout: sys.stdout.write(%s % x) using 'write' you have much more facilities to format the output... I hope this helps Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Jay [EMAIL PROTECTED] wrote: Cold somebody please enlighten me at why code 1 works perfectly and yet code to will not display the gif file. code 2 ---START- from Tkinter import * class App: def __init__(self, root): self.MainFrame = Canvas(root) self.MainFrame.pack(fill=BOTH, expand=1) BackgroundFile = PhotoImage(file=Background.GIF) Tank1 = self.MainFrame.create_image(0, 0, image=BackgroundFile) root = Tk() app = App(root) root.mainloop() ---END- Thanks you need to keep a reference to the photo object on the Python side of things, to keep it from being garbage collected. see the note at the bottom of this page: http://www.effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
On Sat, 08 Apr 2006 21:17:32 -0700, Pythor wrote: (3) legibility: there's no prize for the script with the absolutely minimum number of space characters :-) True. I assume your saying I should make cx,cy,dx, and dy better names. I probably will. Up to now I was just playing around with this, and not really expecting anyone else to read it. No, minimum number of space characters means you don't use enough spaces, not your variable names are too short *wink* Generally speaking, a little bit of whitespace helps makes text more readable, at least for native speakers of languages derived from Latin and other Indo-European languages. Graphic designers tend to manually adjust the spacing between paragraphs, lines, words and even characters, but it isn't necessary to go to that extreme to increase readability. People's tastes vary, and these are not rules, only guidelines, but it is usual to leave one (and sometimes more) blank lines between functions and methods, and even between logical sections of a single function. Within a single line, a good guideline is to leave a single space on either side of pluses and minuses (e.g. x**2 + 5*x - 3). Likewise, a single space on both sides of an equal sign and a single space after commas tend to be usual. As I said, none of these are hard and fast rules, but breaking up the flow of tokens will increase readability immensely. See Guido van Rossum's style guide and the official Python style guide. As usual, Guido is always right, and if his style guide contradicts me, he's wrong but you should follow his guide anyway *smiles* http://www.python.org/doc/essays/styleguide.html http://www.python.org/dev/peps/pep-0008/ As for variables cx, cy, dx and dy, I don't believe that they are unclear. If your function is highly mathematical in nature, I believe it is acceptable if not expected to follow standard mathematical conventions such as r for radius, x and y for real numbers, z for complex, dx for delta (change of) x, etc. If in doubt, when initialising the variable add a comment spelling it out in full. On the other hand, you do have an argument value with default 255, with not even hint for what it is. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to print without blank?
On Sat, 08 Apr 2006 22:54:17 -0700, Ju Hui wrote: I want to print 3 numbers without blank. [snip] how to print 012 ? Method one: accumulate your numbers into a single string, then print it in one go. L = [] for x in range(3): ... L.append(str(x)) ... print ''.join(L) 012 Or even: print ''.join(map(str, range(3))) 012 Or use a list comprehension: print ''.join([str(x) for x in range(3)]) 012 Method two: don't use the print statement, but write directly to standard output. import sys for x in range(3): ... sys.stdout.write(str(x)) ... 012 But notice how this does not write a newline when you are done -- you will have to remember to do it yourself with sys.stdout.write('\n'). Also, print will work with any object, but sys.stdout.write will only work with strings: print 6 6 sys.stdout.write(6) Traceback (most recent call last): File stdin, line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not int -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Decorators, Identity functions and execution...
If I define a decorator like: def t(x) : def I(x) : return x return I and use it like: @t(X) def foo(a) : # definition of foo... pass or maybe this: @t(X) @(Y) def bar(a) : # The definition of bar... Will in encounter much of a penalty in executing 'foo' or 'bar'? If so, is there a way to define t such that Python knows it is the identity function and short-circuit evaluation? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confused by format requires a mapping
[EMAIL PROTECTED] wrote: I'm very new to Python, and unsure how to handle this runtime error below. Pointers in the right direction (RTFM here ... etc) most appreciated. I have an object, called article, that when printed has the following structure: {'title': 'wbk', 'entries': [('http://wbk.opendarwin.org/blog/?p=51', 1), ('http://wbk.opendarwin.org/blog/?p=48', 1), ('http://wbk.opendarwin.org/blog/?p=50', 1), ('http://wbk.opendarwin.org/blog/?p=49',1), ('http://wbk.opendarwin.org/blog/?p=45', 1), ('http://wbk.opendarwin.org/blog/?p=44', 1), ('http://wbk.opendarwin.org/blog/?p=43', 1), ('http://wbk.opendarwin.org/blog/?p=42', 1), ('http://wbk.opendarwin.org/blog/?p=41',1), ('http://wbk.opendarwin.org/blog/?p=40', 1)]}('http://wbk.opendarwin.org/blog/?p=51', 1) DEBUG: Above was a dump of article, prior to return unicode(%(title)s%article) As mentioned in the DEBUG output, my code now returns the following string: unicode(%(title)s%article) However, that appears to conflict with article's structure, and i don't know why? I'm probably missing something fundamental with Python's syntax? the debug output shows a dictionary followed by a tuple, rather than a single value. maybe you should doublecheck what you're really passing to the % formatting operator... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Mysterious EOFError
On Sat, 08 Apr 2006 23:07:54 -0700, Rex Eastbourne wrote: Hi, I'm executing a python script as a cron job. When I run it myself from the command line it works, but when cron executes it I get an EOFError: File /home/rex/cronscript.py, line 6, in ? level = int(raw_input(hello?)) EOFError: EOF when reading a line Because raw_input is waiting for input from the user. I assume that when cron runs a Python script, and there is no actual human user to enter a string in response to raw_input, it raises a EOF error. Written in the docs: http://docs.python.org/lib/module-exceptions.html exception EOFError Raised when one of the built-in functions (input() or raw_input()) hits an end-of-file condition (EOF) without reading any data. (N.B.: the read() and readline() methods of file objects return an empty string when they hit EOF.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated Graph Plotting in Python
Hi, I saw you mentioned gnuplot and did a search on Google of 'gnuplot python-wrapper' which lead me eventually to: http://gnuplot-py.sourceforge.net/ I have not tried it, but if you would try it and report back if it works that might help someone else too. - Cheerio, Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Grant Edwards wrote: On 2006-04-08, Martin v. Löwis [EMAIL PROTECTED] wrote: As for *learning* the languages: never learn a language without a specific inducement. That's silly. Learning (weather a computer language, a natural language, or anything else) is never a bad thing. The more languages you know, the more you understand about languages in general. Learning languages is like any other skill: the more you do it, the better you get at it. I don't exactly see why this is a contradiction. Specific inducement does not necessarily mean that you have to have an external cause to learn a language -- be it your job or whatever. Nobody hinders you from creating that inducement yourself. It's just very hard to properly learn a language without having an idea what to do with it (in fact, I have seen people interested to learn programming utterly fail in doing so because they had absolutely no clue what to program). If you know you are going to write a Python extension, an Apache module, or a Linux kernel module in the near future, start learning C today. If you don't know what you want to use it for, learning it might be a waste of time, as you won't know what to look for if you don't have a specific project in mind. Geeze, when I think of all the things I've wasted my time learning. Well, how many languages have you learnt without writing anything in them? Cheers, Carl Friedrich Bolz -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickle or Mysql
Can i install berkeley db on BSD, I am having a virtual private server, so I have privilates to install on it and do we have management tools like phpmyadmin from berkely db as well, as I am not so good at database management. Thanks Amaltas -- http://mail.python.org/mailman/listinfo/python-list
Writing files on server through CGI
I have a CGI script on server which process a form and writes its content on a file like fp = open(fname, 'w') fp.write('HTMLHEADTITLECool list/TITLE/HEADBODYH2CENTER%s/CENTER/H2BRH3center%s/center/h3/body/html Its working fine, but will it work if the script recieves thousands of request simultaneously. Can this script writes files simultaneusly or will all the request queued and processed one by one. If that is the case then how can I make this script work so that it can process several requests at a time. Thanks Amaltas -- http://mail.python.org/mailman/listinfo/python-list
Re: Curses and Character Handling
Alle 10:46, domenica 09 aprile 2006, [EMAIL PROTECTED] ha scritto: Does anyone know of a solution to this I still learning python, but probably some documentation is the basis of learning, rather than ask at the list. I suggest to see at http://docs.python.org/ for actual and growing python functions and/or builtins. F -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
John Zenger wrote: Your message makes me sad, as if I heard someone say never read a book without a specific inducement; if you know someone is going to ask you about the book, start reading it today, but if you don't know what you are going to use the book for, reading it will be a waste of time. Ah. I wasn't actually talking about reading a C book. I was talking about learning the programming language. You should, of course, read a book about C - but I don't believe you can learn to program C by just reading a book (or any other programming language, for that matter). You will read the book, and might be able to *read* C programs afterwards. To be able to write them, you need practice, and, for that, you need a specific inducement. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
StringIO.readline() returns ''
I'm using StringIO for the first time (to buffer messages recieved from a socket). I thought it would be a simple matter of writing the stuff to the buffer and then calling readline, but that doesn't seem to work: buf = StringIO.StringIO() buf.write(Foo\n) buf.write(Bar\n) buf.flush() buf.readline() '' I expected buf.readline() to return 'Foo\n'. What am I doing wrong? --Max -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Grant Edwards wrote: As for *learning* the languages: never learn a language without a specific inducement. That's silly. Learning (weather a computer language, a natural language, or anything else) is never a bad thing. The more languages you know, the more you understand about languages in general. Learning languages is like any other skill: the more you do it, the better you get at it. Learning a language (whether a natural or a programming language) needs practice, both for reading and for writing. Natural languages are often taught under the guidance of a teacher, to make sure the student gets the practice she needs. In my experience, you won't learn a programming language effectively if you don't get practice (in particular, in writing programs - although reading them might even require *more* practice, especially for C). And, people often don't practice enough (either a natural language, nor a programming language) if they don't have a specific goal in mind what they want to learn the language for. Geeze, when I think of all the things I've wasted my time learning. That's everybody's choice, of course. If you enjoy programming languages on their own merits, you won't need further motivation. However, then you don't post to a newsgroup should I learn this language, but you just go ahead and do it. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Carl Friedrich Bolz wrote: I don't exactly see why this is a contradiction. Specific inducement does not necessarily mean that you have to have an external cause to learn a language -- be it your job or whatever. Nobody hinders you from creating that inducement yourself. It's just very hard to properly learn a language without having an idea what to do with it (in fact, I have seen people interested to learn programming utterly fail in doing so because they had absolutely no clue what to program). This is my experience also. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: StringIO.readline() returns ''
Unknown wrote: I'm using StringIO for the first time (to buffer messages recieved from a socket). I thought it would be a simple matter of writing the stuff to the buffer and then calling readline, but that doesn't seem to work: buf = StringIO.StringIO() buf.write(Foo\n) buf.write(Bar\n) buf.flush() buf.readline() '' I expected buf.readline() to return 'Foo\n'. What am I doing wrong? you forgot to rewind the file: buf = StringIO.StringIO() buf.write(Foo\n) buf.write(Bar\n) buf.seek(0) buf.readline() 'Foo\n' /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Chance Ginger wrote: If I define a decorator like: def t(x) : def I(x) : return x return I ... you get a syntax error. and use it like: @t(X) def foo(a) : # definition of foo... pass that's also a syntax error. or maybe this: @t(X) @(Y) def bar(a) : # The definition of bar... and that's not even fixable. Will in encounter much of a penalty in executing 'foo' or 'bar'? since foo is wrapped, calling foo will call your I function, which in turn calls the original foo. If so, is there a way to define t such that Python knows it is the identity function and short-circuit evaluation? if you don't want to wrap something, don't wrap it: def t(x) : def I(x) : return x if date == friday: return x # don't wrap it return I # wrap it /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Tutorial for absolute beginners
Clodoaldo Pinto wrote: James wrote: On the calculator page you describe the difference between 3.0 / 2 and 3 / 2, but an absolute beginner probably wouldn't know about the difference between integers and floats, or even what the two terms meant. If you don't know much about computers then the fact that they are separate types would probably be surprising... This point is not easy to aproach. The fact is that it is necessary that the beginner knows that there is a differerence between 3 / 2 and 3.0 / 2. I don't want him to now about types, at least not at that stage. I used the term integer for the lack of a better one and I didn't mention float. Any suggestions? Regards, Clodoaldo. Here is a idea. I am not sure if it is a good idea, but you can compare it with the other suggestions for resolving this dilemma. We know that Python is in the process of changing the division operator. The main reason for the change is that the current approach is not intuitive to a newcomer (whether experienced or not). Why not think to the future, and do it like this. Instruct the reader to enter 'from __future__ import division'. You do not have to explain the details, just say that this is the way division will work in the future, and this statement will eventually not be required. Then your example will show that 3/2 = 1.5, which is what they would expect. Then you can mention that, if they just want the integer portion, they can use int(3/2). I think that most people with the slightest understanding of basic arithmetic will relate to this without a problem. My 2c Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: programming puzzles?
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: The trouble with word lists is when you run across something you don't recognize, like ixodid, you can't tell if it's a word or an acronym or an abbreviation. Being in the environmental remediation business, I thought dioxid (which I assume is related to dioxin) to be more plausible as a word. isn't that spelled dioxide in english ? googling for dioxid brings up band homepages, obviously misspelled pages, and non-english pages (it's spelled dioxid in swedish, for example) -- and this page: http://www.morewords.com/word/dioxid/ which says that dioxid is a valid word, and tells me to click on a number of dictionary links to verify that. those links all lead to not found; per- haps you meant dioxide? pages... www.chemfinder.com is probably better place to look for chemistry spellings than dictionaries and they don't list it either. But don't ask me how it made it's way onto the consolidated word list from www.puzzlers.org. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How to determine if a line of python code is a continuation of the line above it
Sandra-24 wrote: I'm not sure how complex this is, I've been brainstorming a little, and I've come up with: If the previous line ended with a comma or a \ (before an optional comment) That's easy to cover with a regex But that doesn't cover everything, because this is legal: l = [ 1, 2, 3 ] and with dictionaries and tuples as well. Not sure how I would check for that programmatically yet. Is there any others I'm missing? Thanks, -Sandra Sandra, in a similar situation I used 'inspect' and 'compile' like so: import inspect def func(*arg, **kwarg): return get_cmd() def get_cmd(): frame = inspect.currentframe() outerframes = inspect.getouterframes(frame) caller = outerframes[1][0] ccframe = outerframes[2][0] ccfname = outerframes[2][1] ccmodule = inspect.getmodule(ccframe) slines, start = inspect.getsourcelines(ccmodule) clen = len(slines) finfo = inspect.getframeinfo(ccframe, clen) theindex = finfo[4] lines = finfo[3] theline = lines[theindex] cmd = theline for i in range(theindex-1, 0, -1): line = lines[i] try: compile (cmd.lstrip(), 'string', 'exec') except SyntaxError: cmd = line + cmd else: break return cmd if __name__ == '__main__': a=0 b=test c=42 cmd=func(a) print cmd cmd=func(a, b, c) print cmd output: cmd=func(a) cmd=func(a, b, c) Regards Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
[Newbie] Referring to a global variable inside a function
Hi experts, I've built a class for parsing a user-defined list of files and matching lines with a user-defined list of regular expressions. It looks like this: code import re import glob class LineMatcher: Parses a list of text files, matching their lines with the given regular expressions and executing associated actions. def __init__(self): # List of file names to parse for matching. self.file_names = [] # Association of reg expressions to actions to execute when match. self.regexp_action = {} def go(self): for file_name in self.file_names: file = open(file_name) for line in file: for regexp, action in self.regexp_action.items(): match = regexp.match(line) if match: action(line, match.groupdict()) def add_files(self, file_pattern): self.file_names.extend(glob.glob(file_pattern)) def add_action(self, regexp_string, action): self.regexp_action[re.compile(regexp_string)] = action /code But then, when I try to use my class using actions with memory it will fail: code import LineMatcher global count count = 0 def line_action(line, match_dictionary): count = count + 1 line_matcher = LineMatcher.LineMatcher() line_matcher.add_files('*') line_matcher.add_action(r'(?Pline.*)', line_action) line_matcher.go() /code The error is: console Traceback (most recent call last): File Test.py, line 12, in ? line_matcher.go() File LineMatcher.py, line 21, in go action(line, match.groupdict()) File Test.py, line 7, in line_action count = count + 1 UnboundLocalError: local variable 'count' referenced before assignment /console How would you do this? Regards, Tito -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Referring to a global variable inside a function
Ernesto García García wrote: But then, when I try to use my class using actions with memory it will fail: code import LineMatcher global count count = 0 def line_action(line, match_dictionary): count = count + 1 line_matcher = LineMatcher.LineMatcher() line_matcher.add_files('*') line_matcher.add_action(r'(?Pline.*)', line_action) line_matcher.go() /code The error is: console Traceback (most recent call last): File Test.py, line 12, in ? line_matcher.go() File LineMatcher.py, line 21, in go action(line, match.groupdict()) File Test.py, line 7, in line_action count = count + 1 UnboundLocalError: local variable 'count' referenced before assignment /console How would you do this? def line_action(line, match_dictionary): global count # make it a module-global variable, not a function-local count = count + 1 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: StringIO.readline() returns ''
Fredrik Lundh wrote: you forgot to rewind the file: Thank you. /F --Max -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
On Sun, 09 Apr 2006 09:51:18 +0200, Fredrik Lundh wrote: Chance Ginger wrote: If I define a decorator like: def t(x) : def I(x) : return x return I ... you get a syntax error. It isn't a syntax error...I tried it before I posted. In fact def t(x) : def I(x) : return x return I is correct. and use it like: @t(X) def foo(a) : # definition of foo... pass that's also a syntax error. Once again this isn't an error assuming you pass in a valid 'X'. or maybe this: @t(X) @(Y) def bar(a) : # The definition of bar... and that's not even fixable. Again you are mistaken. If I say: @t(1) @t(2) def bar(a) : pass It is perfectly valid. Will in encounter much of a penalty in executing 'foo' or 'bar'? since foo is wrapped, calling foo will call your I function, which in turn calls the original foo. If so, is there a way to define t such that Python knows it is the identity function and short-circuit evaluation? if you don't want to wrap something, don't wrap it: def t(x) : def I(x) : return x if date == friday: return x # don't wrap it return I # wrap it /F Decorators are a way to add syntactic sugar to Python, extending it in ways that make it useful for tools. What I am trying to do is lessen the impact on the time used in executing Python code when I use some forms of decorators. -- http://mail.python.org/mailman/listinfo/python-list
wxStyledTextCtrl - Dead?
I have several questions about wxStyledTextCtrl: 1) Is it still being maintained? 2) Where are the docs and tutorials? 3) Is it wxStyledTextCtrl, wx.StyledTextCtrl, StyledTextCtrl, or... ? 4) Is there an alternative? /David -- http://mail.python.org/mailman/listinfo/python-list
Re: fnmatch on filename (without specific extension)
kepioo wrote: I have some files in a directory : Results Log, 11;21AM, Apr 09 2006.txt Results Log, 11;21AM, Apr 08 2006.txt Results Log, 03;59AM, Apr 07 2006.txt otherfile1.txt otherfile2.txt I'd like to copy all the Results Log file, whatever the hour but with a specific day. For instance, today ( 9th april), the script should copy the first file : Results Log, 11;21AM, Apr 09 2006.txt So you need to be able to match on the relevant parts of the file name, which appear to be Results Log at the start of the name, and today's date formatted appropriately for the end, plus .txt as an extension. You seem to know about the existence of the fnmatch module, so what exactly are you having difficulty with? Please post some code showing what you've been able to do so far. (I could also just hand you an answer, but this isn't a difficult problem and you wouldn't learn as much as if you have to walk through it yourself. Of course, inevitably somebody will post a complete answer anyway...) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Round
Hello i´m a beginner in python. With version 14 in SPSS (statistic software) there are the posibility to use python. i want do the following: double NCases NCases=10/6 is this correct in python? Because in SPSS there are an error message. Thank you very much cu Heidi -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + apache + winxp = nogo
Thanks Jim, I indeed did not look in the mailinglist archive (you have to subscribe for that and Google didn't cache it yet). The problem was indeed the missing .DLL's. After adding them to my 'PATH' variable apache was at least able to start. Unfortunately things still don't work. When I try to load a .py file I get the error: == [Sun Apr 09 14:03:46 2006] [error] make_obcallback: could not import mod_python.apache.\n [Sun Apr 09 14:03:46 2006] [error] python_handler: no interpreter callback found. [Sun Apr 09 14:03:46 2006] [error] [client 192.168.2.100] python_handler: Can't get/create interpreter., referer: http://myserver/test/ == This seems more like a bug in mod_python. Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Round
HeidiWeber wrote: Hello i´m a beginner in python. With version 14 in SPSS (statistic software) there are the posibility to use python. i want do the following: double NCases NCases=10/6 is this correct in python? Because in SPSS there are an error message. No, its not correct in python. In python, you don't declare the type of a variable. You statement above would simply be NCases = 10.0 / 6.0 Note the float-literals! If you wouldn't use these, the result would not be ~1.6, but 1 instead, because integer division yields only integers. Depending on which version of python SPSS ships, you should be able to make the division-operator / enforce the usage of floats by putting from __future__ import division on top of your script. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Tutorial for absolute beginners
Duncan Smith wrote: But as you use conversions to float in order to avoid integer division in your code examples, it might be best to explain what's going on, even if you do have to explain the relevant types. I changed the comments in the first program that uses float() to: # The raw_input() function asks the user for a text # As a text can't be multiplied or divided the # float() function tranforms the text into a decimal number I can't imagine anyone (who doesn't already know) looking at the example and not wondering why it returned 1 rather than something else. ... Integer is more mathematical, and more precise. I just looked up some definitions for whole number, and found it can apparently mean positive integer, non-negative integer, or integer. Maybe you can use integer and just put whole number in brackets after it, the first time you use it; as a vague definition? But describing the relevant types and integer division might make your later examples clearer. Now it says integer (whole number) followed by a link to a forum post where this issue can be discussed. http://programming-crash-course.com/integer_versus_float_division Regards, Clodoaldo -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Tutorial for absolute beginners
Frank Millman wrote: We know that Python is in the process of changing the division operator. The main reason for the change is that the current approach is not intuitive to a newcomer (whether experienced or not). Why not think to the future, and do it like this. Instruct the reader to enter 'from __future__ import division'. You do not have to explain the details, just say that this is the way division will work in the future, and this statement will eventually not be required. Then your example will show that 3/2 = 1.5, which is what they would expect. Then you can mention that, if they just want the integer portion, they can use int(3/2). I think that most people with the slightest understanding of basic arithmetic will relate to this without a problem. I included your suggestion in the forum topic that is linked from the division paragraph: http://programming-crash-course.com/integer_versus_float_division -- http://mail.python.org/mailman/listinfo/python-list
Re: Round
No! That is NOT correct Python. For one thing, you do not declare the types in dynamically typed languages. Secondly, if you want floating point division, you need to enter atleast one of the numbers as float. For example 10.0/6 or 10./6 or float(10)/6 You will find the following helpful. http://www.ibiblio.org/obp/thinkCSpy/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Now I just get this error message. AttributeError: 'int' object has no attribute 'image' But the picture appears so I am almost their. ---START--- from Tkinter import * class App: def __init__(self, root): self.MainFrame = Canvas(root) self.MainFrame.pack(fill=BOTH, expand=1) BackgroundFile = PhotoImage(file=Background.GIF) Background = self.MainFrame.create_image(0, 0, image=BackgroundFile) Background.image = BackgroundFile # keep a reference! root = Tk() app = App(root) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated Graph Plotting in Python
[EMAIL PROTECTED] wrote: My python program spits lot of data. I take that data and plot graphs using OfficeOrg spredsheet. I want to automate this task as this takes so much of time. I have some questions. 1. Which is the best graph plotting utility in python or linux. Can I write a code in such a way that my python code automatically gives me a graph. I know little about gnuplot. If you know any better tool without much learning curve please tell me in Linux. I don't know which is best but some options are listed here: http://wiki.python.org/moin/UsefulModules#head-a7e459aeb7e5672e6d431e972a3121670c4dcf1c 2. I want to write a script such that my python code writes to a file, some graph utility like gnuplot takes that data from the file and I get my graph ready made. Do you think its possible ? The Python modules are generally oriented towards a Python API where you pass the data to the plot package directly, rather than creating a file. Under the hood some of them do exactly what you describe; I think gnuplot.py works that way. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: fnmatch on filename (without specific extension)
i agree with you, it is better to find by ourself. i managed to do it, but i left the code at work. i used the re module , using a re.match(Results Log) and a re.search(date) with a function to find the date og the day with the appropriate format. Is it ok to use re for file names? or fnmatch is more efficient? thanks anyway! Nassim -- http://mail.python.org/mailman/listinfo/python-list
Re: Round
thank you very much to you i wish you a nice sunday... cu Heidi -- http://mail.python.org/mailman/listinfo/python-list
Re: how to print without blank?
Steven D'Aprano [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: On Sat, 08 Apr 2006 22:54:17 -0700, Ju Hui wrote: I want to print 3 numbers without blank. [snip] how to print 012 ? Method one: accumulate your numbers into a single string, then print it in one go. L = [] for x in range(3): ... L.append(str(x)) ... print ''.join(L) 012 Or even: print ''.join(map(str, range(3))) 012 Or use a list comprehension: print ''.join([str(x) for x in range(3)]) 012 Method two: don't use the print statement, but write directly to standard output. import sys for x in range(3): ... sys.stdout.write(str(x)) ... 012 But notice how this does not write a newline when you are done -- you will have to remember to do it yourself with sys.stdout.write('\n'). Also, print will work with any object, but sys.stdout.write will only work with strings: print 6 6 sys.stdout.write(6) Traceback (most recent call last): File stdin, line 1, in ? TypeError: argument 1 must be string or read-only character buffer, not int Although the sysout.write() approach is (IMHO) the best, for the OP's case, he could try method three: for x in range(3): print '\b%d' % x, -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: how to print without blank?
thank you all. IT's very helpful to me. import sys def no_space_before(x): ... sys.stdout.softspace = 0 ... return x ... for x in range(3): ... print no_space_before(x), ... 012 -- http://mail.python.org/mailman/listinfo/python-list
I wanna use urllib2 to get a page with a socks 5 proxy, who can give me a sample code ?
I wanna use urllib2 to get a page with a socks 5 proxy,who can give me a sample code ? example, the proxy server is :123.123.123.123 and the port is :1080 and the username/password is : user/pass I want to open http://www.google.com how to write this kind of script? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Chance Ginger [EMAIL PROTECTED] writes: On Sun, 09 Apr 2006 09:51:18 +0200, Fredrik Lundh wrote: Chance Ginger wrote: If I define a decorator like: def t(x) : def I(x) : return x return I ... you get a syntax error. It isn't a syntax error...I tried it before I posted. In fact def t(x) : def I(x) : return x return I is correct. Indeed. This is correct. Fredrick's comment was related to the lack of indentation in your code. and use it like: @t(X) def foo(a) : # definition of foo... pass that's also a syntax error. Once again this isn't an error assuming you pass in a valid 'X'. If your indentation is broken as above it doesn't matter what 'X' is. -- Jorge Godoy [EMAIL PROTECTED] Quidquid latine dictum sit, altum sonatur. - Qualquer coisa dita em latim soa profundo. - Anything said in Latin sounds smart. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Chance Ginger wrote: It isn't a syntax error...I tried it before I posted. In fact def t(x) : def I(x) : return x return I is correct. tabs don't make it through all channels. don't use tabs for indentation when you post to newsgroups or mailing lists. and @(Y) is not valid Python syntax. no amount of indentation will change that. Decorators are a way to add syntactic sugar to Python, extending it in ways that make it useful for tools. that's a rather narrow view of what a decorator does, and doesn't help much in understanding how they work. which is unfortunate, because it's very simple: decorators are simply ordinary callables, and the result of the decoration is whatever the callable returns. in fact, any callable can be used to decorate a function: @str ... def foo(bar): ... pass ... foo 'function foo at 0x00986730' foo(bar) Traceback (most recent call last): File stdin, line 1, in ? TypeError: 'str' object is not callable and it's all done at runtime; there is no magic involved whatsoever. @open ... @str ... def bar(foo): ... pass ... Traceback (most recent call last): File stdin, line 1, in ? IOError: [Errno 2] No such file or directory: 'function bar at 0x009867F0' I am trying to do is lessen the impact on the time used in executing Python code when I use some forms of decorators. if you don't want Python to execute some code, all you have to do is to make sure that it isn't called. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + apache + winxp = nogo
cyberco wrote: Thanks Jim, I indeed did not look in the mailinglist archive (you have to subscribe for that and Google didn't cache it yet). The problem was indeed the missing .DLL's. After adding them to my 'PATH' variable apache was at least able to start. Unfortunately things still don't work. When I try to load a .py file I get the error: == [Sun Apr 09 14:03:46 2006] [error] make_obcallback: could not import mod_python.apache.\n [Sun Apr 09 14:03:46 2006] [error] python_handler: no interpreter callback found. [Sun Apr 09 14:03:46 2006] [error] [client 192.168.2.100] python_handler: Can't get/create interpreter., referer: http://myserver/test/ == You are halfway there. Apache has found the mod_python loadable module, but now *it* can't find the correct mod_python lib files. This may happen when you have several different python versions installed on your system, and mod_python is trying to use the wrong one. If this is the case, adjust the path that apache sees so that the correct python appears first in the path. This seems more like a bug in mod_python. Not a bug - unless you consider poor documentation a bug ;). Your configuration is still not correct. Any suggestions? I'm not sure if our Windows guy reads c.l.p. on a regular basis and I'm rather clueless about Windows issues. Subscribe to the mod_python mailing list. You can always unsubscribe later. :). Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Chance Ginger wrote: On Sun, 09 Apr 2006 09:51:18 +0200, Fredrik Lundh wrote: Chance Ginger wrote: If I define a decorator like: def t(x) : def I(x) : return x return I ... you get a syntax error. It isn't a syntax error...I tried it before I posted. In fact def t(x) : def I(x) : return x return I is correct. You've made the unfortunate mistake of indenting it with tabs, which do not show up on some newsreaders. I see the tabs in Google; people using Microsoft Outlook do not. Always use spaces when posting, and use them in your code as well. Spaces are the current recommended practice, and in the future tabs might become illegal. I'd prefer tabs myself, but it's more important to respect community standards than to stick to some silly preference you have. Decorators are a way to add syntactic sugar to Python, extending it in ways that make it useful for tools. What I am trying to do is lessen the impact on the time used in executing Python code when I use some forms of decorators. One suggestion. Have you run the script, determined it's too slow, and are trying to optimize? If not (and it doesn't sound like you are), I suggest that it's too soon to worry about whether this decorator has any overhead. You may end up doing a lot of work optimizing that will ultimately have very little benefit. Having said that, this decorator will not affect calling overhead at all. The decorator is applied when the module is loaded, not when the decorated function is called. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Michael Tobis wrote: Proving yet again that it's possible to write Fortran in any language. Ouch... You aren't getting any benefit from numpy or python here. Are you aiming for speed or legibility? Speed will be a necessity, eventually. I was just really aiming for something that works, and that I am capable of writing. Also, with this code, you are using radius for the dimensions of the enclosing box, as well as the radius of the circle, so it's guaranteed to not to actually produce a whole circle. Recall what python does with negative indices! I'm not sure what you mean here. It produces an eighth-circle, and then plots each point in the 8 symmetrical positions on the circle. Except for the (dx+1) point made above, what piece of the circle is missing? I'll bet this does the trick for you and runs faster than what you've got def circle(rad = 5,max_x = 20, max_y = 20,cx = 10, cy= 10, value=255): radsq = rad * rad return numpy.array([[((x - cx) ** 2 + (y - cy) ** 2 radsq) and value or 0 for x in range(max_x)] for y in range(max_y)],'u') I think the pure numpy solution should be something like (untested) def circle(rad = 5,max_x = 20, max_y = 20,cx = 10, cy= 10, value=255): def sqdist(x,y): return (x - cx) * (x - cx) + (y - cy) * (y - cy) distarray = numpy.fromfunction(sqdist,(max_y,max_x)) return numpy.asarray(numpy.choose(greater(distarray,rad*rad),(0,value),'u') I'll take a look at both of these. At this point, I can't quite wrap my head around what you're doing for either one. Neither approach will get you the eightfold speedup that the messy code was aimed at, but in practice they will spend less time at the interpreter level and will likely run faster. mt -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Steven D'Aprano wrote: No, minimum number of space characters means you don't use enough spaces, not your variable names are too short *wink* Hmm. Guess I can't read too well. Within a single line, a good guideline is to leave a single space on either side of pluses and minuses (e.g. x**2 + 5*x - 3). Likewise, a single space on both sides of an equal sign and a single space after commas tend to be usual. What I produced was natural for my fingers, but I can see that it's difficult on the eyes. I'll try to remember that. As for variables cx, cy, dx and dy, I don't believe that they are unclear. If your function is highly mathematical in nature, I believe it is acceptable if not expected to follow standard mathematical conventions such as r for radius, x and y for real numbers, z for complex, dx for delta (change of) x, etc. If in doubt, when initialising the variable add a comment spelling it out in full. On the other hand, you do have an argument value with default 255, with not even hint for what it is. Well, value is just a value. It's the number that get's punched into the array for any points within the circle. I didn't have any better name I could think of. -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Pythor wrote: You aren't getting any benefit from numpy or python here. Are you aiming for speed or legibility? Speed will be a necessity, eventually. I was just really aiming for something that works, and that I am capable of writing. any special reason you cannot use an existing graphics library ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Sandra-24 wrote: C/C++ is used for a lot of things and not going anywhere. I recommend you learn it not because you should create applications in C or C++, but because it will increase your skills and value as a programmer. I recommend you even spend a few weeks with an assembly language, for the same reason. Back in the day we wrote _way_ too much in assembly language, often simply because there was no other language capable of doing, for example an assembly language. C has replaced assembly language for most of an operating system. In the SIGPLAN conference where C was first publicly introduced, a later talk began with the speaker, who was talking about his new portable macro system, said, Everyone at this conference should find out about 'C', it makes this work obsolete. What C has as virtues are simple clear semantics, an obvious map to the machine code representing each language feature, a language simple enough to read through to the machine in the sense that you can read a C program and not have a little section in the pure language take a surprising amount of time (no surprise delays), and you can express most of the bag of tricks assembly language programmers used at the time to write their operating systems, compilers, One other immense difference in C was that the language had very few magic functions (setjmp and longjmp are the obvious bits-o-magic). For the most part, the entire library could be written in the language C itself. Further, there was a clear mapping between assembly language and C; you could write a function in assembly that could be called from C, and there was so little necessary infrastructure that you could also write a function in C that could be called from assembly. C can express neither exceptions nor coroutines (nor their fancy cousin, continuations), which could be and were expressed in assembly. Nor does C provide memory management. A few library functions give you some primitives to roll your own, but garbage collection is out of the question (despite Hans Boehm), because the language does not carry enough infrastructure to find type information through introspection. In exchange for these losses, the C programmer can write code that executes in response to an external signal and yet does not create a total hash of the internal memory structures. That kind of thing is important in an OS, and something few languages (including C++) can do. If you intend to study C++, study C first (it is easier to grasp), as almost everything you learn in C can be used in C++. C++ is a big language, while C is a small one; it will take much longer to know C++ even though C++ started with the goal of being C with objects. If you are interested in languages, reading the Design and Evolution of C++ is a great base; it explains how C++ got the way it is from its initial design goals. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
First, thanks for the tip of 'tabs'. I keep forgetting Outlook has some interesting rules about displaying text. Thanks for the comment about happening at load time. That resolved the problem (in my thinking)! I don't believe I have an issue at all... Peace, CG. On Sun, 09 Apr 2006 08:52:18 -0700, Carl Banks wrote: Chance Ginger wrote: On Sun, 09 Apr 2006 09:51:18 +0200, Fredrik Lundh wrote: Chance Ginger wrote: If I define a decorator like: def t(x) : def I(x) : return x return I ... you get a syntax error. It isn't a syntax error...I tried it before I posted. In fact def t(x) : def I(x) : return x return I is correct. You've made the unfortunate mistake of indenting it with tabs, which do not show up on some newsreaders. I see the tabs in Google; people using Microsoft Outlook do not. Always use spaces when posting, and use them in your code as well. Spaces are the current recommended practice, and in the future tabs might become illegal. I'd prefer tabs myself, but it's more important to respect community standards than to stick to some silly preference you have. Decorators are a way to add syntactic sugar to Python, extending it in ways that make it useful for tools. What I am trying to do is lessen the impact on the time used in executing Python code when I use some forms of decorators. One suggestion. Have you run the script, determined it's too slow, and are trying to optimize? If not (and it doesn't sound like you are), I suggest that it's too soon to worry about whether this decorator has any overhead. You may end up doing a lot of work optimizing that will ultimately have very little benefit. Having said that, this decorator will not affect calling overhead at all. The decorator is applied when the module is loaded, not when the decorated function is called. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Jay wrote: Now I just get this error message. AttributeError: 'int' object has no attribute 'image' But the picture appears so I am almost their. ---START--- from Tkinter import * class App: def __init__(self, root): self.MainFrame = Canvas(root) self.MainFrame.pack(fill=BOTH, expand=1) BackgroundFile = PhotoImage(file=Background.GIF) Background = self.MainFrame.create_image(0, 0, image=BackgroundFile) Background.image = BackgroundFile # keep a reference! the example on that page attaches the image to a widget instance, not a canvas object handle (which is an integer; unlike user-defined classes, integers don't allow you to attach arbitrary attributes to them). if you just want to display a single image, just attach it to self: BackgroundFile = PhotoImage(file=Background.GIF) Background = self.MainFrame.create_image(0, 0, image=BackgroundFile) self.image = BackgroundFile # keep a reference! if you want to display multiple images on the canvas, use a dictionary or a list to hold active image references. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: I wanna use urllib2 to get a page with a socks 5 proxy, who can give me a sample code ?
Ju Hui wrote: I wanna use urllib2 to get a page with a socks 5 proxy,who can give me a sample code ? example, the proxy server is :123.123.123.123 and the port is :1080 and the username/password is : user/pass I want to open http://www.google.com how to write this kind of script? I'm pretty sure that urllib2 doesn't work with SOCKS proxies of any kind. I think you'll have to use pycurl (extension library - not in standard lib). This is mcuh more powerful, but not so simple to use. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Receiving emails with attachments
Gerard, I tried to run your code but my interpreter couldn't locate the maildocument module. Is it included in Python standart library or should I install it from other place? Thanks, Tomer -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Carl Banks wrote: Having said that, this decorator will not affect calling overhead at all. The decorator is applied when the module is loaded, not when the decorated function is called. to be precise, the decorator is applied when the def statement is exe- cuted (that is, when the decorated function object is created). this may be load time, or, for nested functions, some other time. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Tutorial for absolute beginners
Clodoaldo Pinto wrote: Duncan Smith wrote: But as you use conversions to float in order to avoid integer division in your code examples, it might be best to explain what's going on, even if you do have to explain the relevant types. I changed the comments in the first program that uses float() to: # The raw_input() function asks the user for a text # As a text can't be multiplied or divided the # float() function tranforms the text into a decimal number Hmmm, maybe a picky point for a newbie, but since there actually is a decimal module now, you might want to change the description of float(). -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Martin v. Löwis wrote: As for *learning* the languages: never learn a language without a specific inducement. If you know you are going to write a Python extension, an Apache module, or a Linux kernel module in the near future, start learning C today. If you don't know what you want to use it for, learning it might be a waste of time, as you won't know what to look for if you don't have a specific project in mind. I don't know if I completely agree with you, but I definitely understand your point. I started learning C# for no reason, just because I'm interested in programming. A year later, I never really used it much because I didn't have a reason to. Now I've moved on to Python (actually, I was going to start learning Python a while ago, but I was afraid it would interfere with learning C#). So here I am now thinking about C, but I also don't want it to interfere with Python. I like Python and want to stick with it, which is why I'm desperately looking fore exercises and puzzles so I can use it. It's just that I obessively like to learn new things, and I keep moving on to new subjects once I've 'learned' something well enough. I know Python well enough, but for no real reason, so I think I'm going to stick with it and keep using it, because it's fun. -- http://mail.python.org/mailman/listinfo/python-list
How Relevant is C Today? I still need it for Writing!
How Relevant is C Today? I still need it for Writing! -- Regards, Casey -- http://mail.python.org/mailman/listinfo/python-list
Re: Receiving emails with attachments
On 8 Apr 2006 13:24:20 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: want to develop a script which will receive emails with attachmentsfrom my POP3 account, perform certain actions on it and email it back to someone else.However, I'm not familiar with any Python library which does it. Couldyou a guide me to a relevant library which can handle emails? The poplib module has already been mentioned for downloading from a pop3 mailbox For sending mail you will need the smtplib module. Depending on what actions you need to perform on each email, the email module may also be useful. HTH :)-- Tim Williams -- http://mail.python.org/mailman/listinfo/python-list
Creating an event loop
Hello! I am currently wondering how to write something like an event loop. For example, if I want to write a function that checks whether a file was added or removed in a directory I would think of a while 1: ... construct that checks the mtime of the directory. Is this the right way to achieve the exepected result or are there any better ways? Cheers, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Fredrik Lundh wrote: Pythor wrote: You aren't getting any benefit from numpy or python here. Are you aiming for speed or legibility? Speed will be a necessity, eventually. I was just really aiming for something that works, and that I am capable of writing. any special reason you cannot use an existing graphics library ? /F Well, I'm not really interested in pretty pictures, but in the resulting array. It might be worth using a graphics library and then converting from an image to an array when I'm done. I've been playing with PIL for that. But I wanted to see what I could do on my own, too. In addition, I'll eventually need some functions that are definitely not in a standard graphics library, and I wanted to get started with something I thought was relatively simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Receiving emails with attachments
[EMAIL PROTECTED] wrote: Gerard, I tried to run your code but my interpreter couldn't locate the maildocument module. Is it included in Python standart library or should I install it from other place? Thanks, Tomer Sorry Tomer, I was just suggesting you read it through as an example, didn't think you'd be interested in the whole shebang! PopClient was part of a half-baked project whose intent was to keep an eye on my technology-shy parents' emails and - wait for it - *post* them any attachments that were important!! Emails they can do, attachments not. But it was a good learning exercise. All the necessary files are here: http://gflanagan.net/site/python/pagliacci/ Coming from C# I was used to 'one class - one file', but this will be updated one of these days. This is the particular file you want: http://gflanagan.net/site/python/pagliacci/MailDocument.html which requires: http://gflanagan.net/site/python/pagliacci/ElementWrapper.html and both these require the elementtree package which will soon be part of the standard library, but now you can get it here: http://effbot.org ( I also have a simple viewer based on XSLT, CherryPy and a CherryPy filter called Picket but it's not very sophisticated.) Hope that's enough to get you started. Gerard -- http://mail.python.org/mailman/listinfo/python-list
Best Python web-hosting?
I don't need that much web space. I don't need Zope/Plone. But, I want a site that offers more than just CGI. And I would like support for recent Python releases. Price is an issue, that's one reason I've been reluctant to use python for web-sites, hosting seems to be more expensive than with php. -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE on Fedora Core 5
In article [EMAIL PROTECTED], Fredrik Lundh [EMAIL PROTECTED] wrote: I have just installed FC5 on a new computer. I can access Python by typing Python in a terminal window, but I can't find any way of getting to IDLE. Can anyone help? $ yum provides idle can help, I think. it'll probably tell you to do $ yum install python-tools I've done that, thanks, but I still can't find out how to get to python-tools. I'm obviously missing a trick somewhere. -- David Wild using RISC OS on broadband -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Python web-hosting?
http://www.westhost.com/ You get a virtual private server with them, so you can install whatever you want. cheap too. -- http://mail.python.org/mailman/listinfo/python-list
Notification bubbles via dbus in Gnome on Ubuntu.
I'd like to be able to pop up a notification bubble like the ones used by Ubuntu for 'updates available' etc. In particular I'd like to be able to use them to warn users of other machines that I have started a background session for maintenance and not to worry if the computer seems to be doing things that aren't related to their session. I believe these bubbles are handled by the notification-daemon, listening on dbus for messages from libnotify0. Can this be controlled from Python via the Python-Dbus bindings? I haven't been able to turn up any detail or example programs yet; am I completely on the wrong track or can it be done? If it can, might it make a reasonable project for me as a complete beginner with Python though some experience with other languages? Or would I be biting off more than a beginner is likely te be able to deal with? Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Hi John It's just that I obessively like to learn new things, and I keep moving on to new subjects once I've 'learned' something well enough. Ha! So learn 'Perl' then - you'll never ever get over this point ... ;-)) And if you, against all odds, think you master it now - zon, a new Perl Version with completely new syntax shows up ... I know Python well enough, but for no real reason, so I think I'm going to stick with it and keep using it, because it's fun. At which level in the 'python challenge' did you get stuck - and why? Regards M. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Python web-hosting?
http://www.python-hosting.com/ I haven't used them myself, but recent research that I did made them look like good candidates. -- http://mail.python.org/mailman/listinfo/python-list
Problems with current value of wx.SpinCtrl and EVT_SPIN
Hello, I am new to Python/wxPython and am experiencing first problems. I have a dialog which includes a SpinCtrl and a Slider. I want the Slider to affect the SpinCtrl and vice versa (http://wiki.wxpython.org/index.cgi/ChallengeDemos#Part1). The code I wrote does, however, not work correctly. The event EVT_SPIN is never handled (even though I wrote a handler), and in the handler of EVT_SCROLL_CHANGED I do not obtain the modified value, but the value before the control has changed. Any feedback would be greatly appreciated. To clarify my problem, here's the code (Python2.4, wxPython 2.6) : import wx class AppFrame(wx.Frame): def OnSpinGeneral(self, event): b = wx.MessageBox(never reached) def OnSpin(self, event): # I tried to use Skip so that the changing of the value would take place before # I invoke GetValue(), however this has no effect event.Skip() print self.spin.GetValue() self.slider.SetValue(self.spin.GetValue()) def OnScrollChanged(self, event): self.spin.SetValue(self.slider.GetValue()) def __init__(self): wx.Frame.__init__( self, None, -1, , #size=FRAME_SIZE, style=wx.DEFAULT_FRAME_STYLE ) self.sizer = wx.BoxSizer( wx.VERTICAL ) self.spin = wx.SpinCtrl(self, min = 0, max = 50) self.slider = wx.Slider(self, 1, 6, 0, 50) self.sizer.Add(self.spin) self.sizer.Add(self.slider) self.Bind(wx.EVT_SCROLL_CHANGED, self.OnScrollChanged, self.slider) self.Bind(wx.EVT_SPIN_UP, self.OnSpin, self.spin) self.Bind(wx.EVT_SPIN_DOWN, self.OnSpin, self.spin) self.Bind(wx.EVT_SPIN, self.OnSpinGeneral, self.spin) self.SetSizer(self.sizer) self.SetAutoLayout(1) self.Show(1) app = wx.PySimpleApp() frame = AppFrame() app.MainLoop() -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Hi Scott your summary looks very concise and good to read. I'd like to make some minor additions, C can express neither exceptions nor coroutines (nor their fancy cousin, continuations), which could be and were expressed in assembly. Nor does C provide memory management. A few library functions give you some primitives to roll your own, but garbage collection is out of the question (despite Hans Boehm), because the language does not carry enough infrastructure to find type information through introspection. So, al-imho, C 'abstracts out' some consistent 'von-Neumann' or 'Harvard-' machine from any architecture where its ported to. And that is - imho - the main strength of C. It covers well most machine code vs. C instruction mapping (~1:1), and RAM storage vs. coressponding data representation (1:1), as you said partially. It can't handle any aspect beyond these simple mappings in its language core, this is where more complex bulding blocks (libraries) will come into play. In exchange for these losses, the C programmer can write code that executes in response to an external signal and yet does not create a total hash of the internal memory structures. That kind of thing is important in an OS, and something few languages (including C++) can do. If you intend to study C++, study C first (it is easier to grasp), as almost everything you learn in C can be used in C++. C++ is a big language, while C is a small one; it will take much longer to know C++ even though C++ started with the goal of being C with objects. If you are interested in languages, reading the Design and Evolution of C++ is a great base; it explains how C++ got the way it is from its initial design goals. I would say, from my own experience, that you wouldn't use all C++ features in all C++ projects. Most people I know would write C programs 'camouflaged' as C++, that is: write clean simple C - and use some C++ features e.g, class bound methods for interfaces - but no inheritance at all (use compound objects) and no exceptions (handle errors 'the olden way'). Regards M. -- http://mail.python.org/mailman/listinfo/python-list
Re: 32-bit python on Opteron, Solaris 10?
Gary Robinson wrote: I'm in the market for a server to run some python code which is optimized via psyco. Sun T2100 servers come with Solaris 10, which comes with python pre-installed. You can always install a 32bits version of Linux or Solaris on the X2100 yourself. The X2100 is even certified to run on it . cf http://www.sun.com/servers/entry/x2100/os.jsp -- http://mail.python.org/mailman/listinfo/python-list
Re: Mysterious EOFError
Thanks. Do you know of a solution to this? I tried the following, which I found on this newsgroup: # lines = open(sys.argv[1]).readlines() # sys.stdin = open('/dev/tty') a = raw_input('Prompt: ') # sys.stdin = os.fdopen(3) a = raw_input('Prompt: ') # What I want to do is execute a scheduled task that prompts me for something and allows me to enter it and have it stored somewhere. I'm on Ubuntu Linux. Thanks in advance! Steven D'Aprano wrote: On Sat, 08 Apr 2006 23:07:54 -0700, Rex Eastbourne wrote: Hi, I'm executing a python script as a cron job. When I run it myself from the command line it works, but when cron executes it I get an EOFError: File /home/rex/cronscript.py, line 6, in ? level = int(raw_input(hello?)) EOFError: EOF when reading a line Because raw_input is waiting for input from the user. I assume that when cron runs a Python script, and there is no actual human user to enter a string in response to raw_input, it raises a EOF error. Written in the docs: http://docs.python.org/lib/module-exceptions.html exception EOFError Raised when one of the built-in functions (input() or raw_input()) hits an end-of-file condition (EOF) without reading any data. (N.B.: the read() and readline() methods of file objects return an empty string when they hit EOF.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Referring to a global variable inside a function
How would you do this? def line_action(line, match_dictionary): global count # make it a module-global variable, not a function-local count = count + 1 /F OK, I had put it on the global block. Thanks, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Mirco Wahab wrote: I would say, from my own experience, that you wouldn't use all C++ features in all C++ projects. Most people I know would write C programs 'camouflaged' as C++, that is: write clean simple C - and use some C++ features e.g, class bound methods for interfaces - but no inheritance at all (use compound objects) and no exceptions (handle errors 'the olden way'). Of course. C++ is a hybrid language by design, not only an object oriented language, not only a language with exceptions, not only a language with compile time metaprogramming etc. You don't have to use all the features of C++ to make a real C++ program. Even for writing C programs, C++ is still a better choice (in my opinion). If you want to, you can keep things simple, and plain C-ish, and still benefit from better type safety etc. In my everyday work, I am forced to use a C90 only compiler, and everyday I miss some C++ feature that wouldn't make my program any more complex, quite the opposite. These are features like const, no default extern linkage, more typesafe enums etc. You can put upon yourself to program in a C style, but whenever you miss something, you can always wrap that up behind an abstraction such as a class etc., and still maintain C-like semantics. Say I wanted an Ada-like integer type that only runs from 1 to 100. I could make such a beast in C++, and then use it just as an ordinary int in my C style program. I could even make this beast _be_ an ordinary int in release builds when I was sure (yeah right) that the code was bugfree. This gives expressibility and preciseness in specification. You let the compiler do the work for you. And you still maintain performance. You can't do this in C at all. And there are a million more examples. In practice, the combination of Python and C++ covers most of what I need to do in most situations. But I still wish that C++ offered a lot more of those zero-overhead features that it might as well offer, that the compiler just as well can do. It could learn from Ada in this regard. /David -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Web Services from Python
Can you tell us more about SOAPpy bug ? Is it about authentication ? Ivan Zuzak a écrit : ... I need a package/tool that generates web service proxies that will do all the low-level HTTP work. (Someting like the WSDL.EXE tool in .NET Framework) The ZSI and SOAPy packages [1] that i found (should) have those functionalities but either have a bug (SOAPy) or either do not work for arbitrary web services (ZSI). ... -- http://mail.python.org/mailman/listinfo/python-list
Re: wxStyledTextCtrl - Dead?
The wxPython Demo (http://prdownloads.sourceforge.net/wxpython/wxPython-demo-2.6.3.2.tar.gz) still contains the wxStyledTextCtrl: wx.stc.StyledTextCtrl The demo is probably also a good example of how to use wxStyledTextCtrl. Basic information can be found on http://www.yellowbrain.com/stc/init_repr.html Regards. David Rasmussen schrieb: I have several questions about wxStyledTextCtrl: 1) Is it still being maintained? 2) Where are the docs and tutorials? 3) Is it wxStyledTextCtrl, wx.StyledTextCtrl, StyledTextCtrl, or... ? 4) Is there an alternative? /David -- http://mail.python.org/mailman/listinfo/python-list
Re: efficiency of range() and xrange() in for loops
Alan Morgan wrote: How would xrange(100).remove(1) work? One way is by first converting the xrange to a list. If we think of the xrange as an efficient and space lean way to store certain types of lists then it isn't unreasonable to return a regular list when the conditions no longer hold. do you understand Python's object model to be able to suggest how such a conversion could be done, or is that someone else's problem ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: The World's Most Maintainable Programming Language
I thought the paragraph about provability was interesting. Presumably the author refers to proofs in the spirit of A Discipline of Programming from Djikstra, 1976. Unfortunately, I don't think anyone has writting much about this since the 70s. I'd be interested to learn if anyone's tried to write weakest precondition style specifications for python (builtin functions, for, lambda, etc). Or perhaps there's some easier to understand medium? It's worth noting that the author makes proving correctness sound like a trivial task, which of course it's not. Consider def collatz(n,i=0): if n==1: return i elif (n%2)==0: return collatz(n/2,i+1) else: return collatz((3*n+1)/2,i+1) It is currently unknown whether this even terminates in all cases. -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated Graph Plotting in Python
[EMAIL PROTECTED] writes: 1. Which is the best graph plotting utility in python or linux. matplotlib (provided it does the type of graphs you need, which is likely) 'as -- http://mail.python.org/mailman/listinfo/python-list
Re: Receiving emails with attachments
Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to determine if a line of python code is a continuation of the line above it
Sandra-24 wrote: I'm not sure how complex this is, I've been brainstorming a little, and I've come up with: from tokenize import generate_tokens, NL, NEWLINE from cStringIO import StringIO def code_lines(source): Takes Python source code (as either a string or file-like object) and yields a tuple of (is_new_logical, code) for each physical line of code. if isinstance(source, basestring): source = StringIO(source) buffer = [] new_logical = True for token_type, source, sloc, eloc, line in \ generate_tokens(source.readline): buffer.append(source) if token_type == NL: yield new_logical, ''.join(buffer) buffer = [] new_logical = False elif token_type == NEWLINE: yield new_logical, ''.join(buffer) buffer = [] new_logical = True if buffer: yield new_logical, ''.join(buffer) -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + apache + winxp = nogo
Hi Jim, Thanks, I'll sign up for the mailinglist, but to finish the story here: - I only have one version of Python installed - From the Python interpreter I can import the mod_python module just fine - At starup the Apache log states: [Sun Apr 09 22:16:38 2006] [notice] Apache/2.0.55 (Win32) mod_python/3.2.5b Python/2.4.2 configured -- resuming normal operations [Sun Apr 09 22:16:38 2006] [notice] mod_python: Creating 8 session mutexes based on 0 max processes and 250 max threads. Cheers, cyberco -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + apache + winxp = nogo
yep -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing files on server through CGI
On Sun, Apr 09, 2006 at 12:35:21AM -0700, [EMAIL PROTECTED] wrote: I have a CGI script on server which process a form and writes its content on a file like fp = open(fname, 'w') fp.write('HTMLHEADTITLECool list/TITLE/HEADBODYH2CENTER%s/CENTER/H2BRH3center%s/center/h3/body/html Its working fine, but will it work if the script recieves thousands of request simultaneously. I assume that's a question. No, it won't. If you open a file for writing no other program can write to it. Can this script writes files simultaneusly or will all the request queued and processed one by one. Sorry, no. What is your intent? Usually you either have CGIs that output HTML directly or scripts that update an HTML file. But CGIs that write to a HTML file... that looks pretty uncommon. Don't worry about updating a static HTML file though. If you are using a decent web server like Apache it will have the file cached and try to read it once you are done changing it. But don't use CGIs for that. Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Brill, Thanks for the help -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating an event loop
Fabian Steiner wrote: I am currently wondering how to write something like an event loop. For example, if I want to write a function that checks whether a file was added or removed in a directory I would think of a while 1: ... construct that checks the mtime of the directory. Is this the right way to achieve the exepected result or are there any better ways? That's fine for a start, provided you always insert a small time.sleep() call so that you don't use up all the CPU time wastefully checking for something that happens very rarely. In the end, it's a tradeoff between CPU usage and latency, because if you use (for example) time.sleep(5), you won't waste much time but you will also take up to 5 seconds to notice that the directory has changed. Usually values like 0.1 (100ms) work well for things that need a quick response, while 2s works nicely for things that don't. Even Python is pretty unnoticeable if it wakes up only every two seconds for a brief bit of processing. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with current value of wx.SpinCtrl and EVT_SPIN
blackno666 wrote: I am new to Python/wxPython and am experiencing first problems. I have a dialog which includes a SpinCtrl and a Slider. I want the Slider to affect the SpinCtrl and vice versa (http://wiki.wxpython.org/index.cgi/ChallengeDemos#Part1). The code I wrote does, however, not work correctly. The event EVT_SPIN is never handled (even though I wrote a handler), and in the handler of EVT_SCROLL_CHANGED I do not obtain the modified value, but the value before the control has changed. Does it *appear* to work? That is, if you run it, does the slider move if you click on one of the spinner buttons, and does the spinner value change when you move the slider (and release the button)? Because that's what happens for me, so I'm not sure what it is that you expected it to do... (wxPython 2.6.1.0 on WinXP SP2) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with current value of wx.SpinCtrl and EVT_SPIN
Yes, it works. However buggy. When the slider is set to 0 and the up button is pressed in the SpinCtrl, the value in the SpinCtrl will be 1, but the slider will not move. There's also a discrepancy between the value displayed in the SpinCtrl and the value output by print self.spin.GetValue(). When playing with this code I also noticed that I was not able change the behaviour of the up and down buttons. I expected that if I modify OnSpin in the following way: def OnSpin(self, event): pass That pressing the spin buttons would have no effect. However, the value is still increased or decreased -- http://mail.python.org/mailman/listinfo/python-list
ANN: Speedometer 2.4 - bandwidth and download monitor
Announcing Speedometer 2.4 -- Speedometer home page: http://excess.org/speedometer/ Download: http://excess.org/speedometer/speedometer.py New in this release: - New -z option treats files that don't exist as zero length so speedometer will not wait for them to be created at startup. - Multiple file taps may now be used stacked vertically in the same column. About Speedometer = Speedometer is a console bandwidth and file download progress monitor with a logarithmic bandwidth display and a simple command-line interface. Speedometer requires Python 2.1 or later and Urwid 0.8.9 or later for full-console bar graph display. Urwid may be downloaded from: http://excess.org/urwid/ Speedometer is released under the GNU LGPL. -- http://mail.python.org/mailman/listinfo/python-list
Re: how relevant is C today?
Mirco Wahab wrote: At which level in the 'python challenge' did you get stuck - and why? Ugh, don't remind me! :) I'm stuck on level 12, which is yet another image processing puzzle. I'm getting tired of those, and I think it's really a shame that there is a reliance on image puzzles rather than simply doing some coding to figure out an algorithm, for example. (I really enjoyed writing my own function to figure out the Morris sequence.) Level 11 was an image puzzle that I flat-out cheated on to move forward, and now here I am again at 12, another complex image puzzle, and I can't find the answer for it. If anyone feels like emailing me with the solution, I certainly won't be offended. :) I just hope that later puzzles stop relying on PIL and start requiring that you do some real coding with other modules, or even with just the core language itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Python web-hosting?
walterbyrd wrote: I don't need that much web space. I don't need Zope/Plone. But, I want a site that offers more than just CGI. And I would like support for recent Python releases. Price is an issue, that's one reason I've been reluctant to use python for web-sites, hosting seems to be more expensive than with php. I was testing out http://www.devisland.net/ and it's pretty nice. They installed the latest versions of Python, mod_python and mysqldb at my request, and support was good. Only real problem is it's too expensive for the space you get (about $5/month for 100MB), but you said space wasn't much of an issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with current value of wx.SpinCtrl and EVT_SPIN
Just found a solution to the problem: when using wx.EVT_SPINCTRL instead of wx.EVT_SPIN_UP, wx.EVT_SPIN_DOWN or wx.EVT_SPIN the program behaves correctly. wxWidget documentation for wxSpinCtrl states that You may also use the wxSpinButton event macros, however the corresponding events will not be generated under all platforms; I ran the program on WinXP SP2. However, the events seem to be handled (at least EVT_SPIN_UP, wx.EVT_SPIN_DOWN). So I do not understand why handling these events leads to a buggy behaviour. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
On Sun, 09 Apr 2006 08:52:18 -0700, Carl Banks wrote: it's more important to respect community standards than to stick to some silly preference you have. What happens when the community standard is a silly preference? I object to the suggestion that community standards (that is, a standard not even designed by a committee, merely evolved by a mob) is necessarily worthy of respect. As it turns out, regarding this particular silly preference (community or private), I always remember that communication is the purpose of email (and, believe it or not, Usenet), and the use of tabs in some buggy news readers can cause the failure of communication. Hence I use spaces when posting code. The rest of the time, particularly in my private coding, my preference (whatever it is) is no more or less irrational than the other preference. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 09 Apr 2006 08:52:18 -0700, Carl Banks wrote: it's more important to respect community standards than to stick to some silly preference you have. What happens when the community standard is a silly preference? I object to the suggestion that community standards (that is, a standard not even designed by a committee, merely evolved by a mob) is necessarily worthy of respect. Design by committee has far from a stellar track record. On the Internet, most of the really good stuff has come from the mobs. As it turns out, regarding this particular silly preference (community or private), I always remember that communication is the purpose of email (and, believe it or not, Usenet), and the use of tabs in some buggy news readers can cause the failure of communication. Hence I use spaces when posting code. As you should. It matters not whether news readers that can't handle tabs are buggy or not. The fact is that they exist. One of the most basic maxims on the Internet has always been, Be liberal in what you accept, be conservative in what you produce. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorators, Identity functions and execution...
Em Dom, 2006-04-09 às 08:52 -0700, Carl Banks escreveu: You've made the unfortunate mistake of indenting it with tabs, which do not show up on some newsreaders. I see the tabs in Google; people using Microsoft Outlook do not. He does not need to know that some poor designed newsreaders mess up with tabs at will. Python supports tab indentation and it's not forbidden to use it (if it was, support for it in the Python codebase would have been removed long time ago). I don't like to code with tab-indents, I use 4 spaces, but I don't press space four times each time I need to indent something, I just press Tab and the editor does the clunky part for me. The problem is that most (if not all) mail programs/newsreaders don't convert tabs to spaces, they don't even keep the indentation of the last line, so nobody has the obligation of opening its IDE or hitting dozens of times the space key just to post a message to the list. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED]
please put me on your mailing list -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
It's also possible to write microprocessor assembly language in any other language. The following code generates the OP's list of points with nothing more complicated than integer addition/subtraction inside the loop. It also does the right thing if the radius is not an integer, and avoids the OP's 0.71 approx == sin(45 deg) aka 1/sqrt(2) caper. Wrt your Pythonic suggestion: I'll bet this does the trick for you and runs faster than what you've got: You lose on does the trick (should be = radsq). As for the second clause, a prerequisite to testing that is to get the OP to say what his typical radius and typical enclosing box size are (and get your point that they should not be the same). Cheers, John # def octant(radius): # assert radius = 0 # filllist = [] # dx = int(radius) # dy = 0 # trigger = dx * dx - int(radius * radius) # dx_squared_delta = dx + dx - 1 # dy_squared_delta = 1 # while dy = dx: # if trigger = 0: # for x in range(dy, dx+1): # filllist.append((x, dy)) # dy += 1 # trigger += dy_squared_delta # dy_squared_delta += 2 # else: # dx -= 1 # trigger -= dx_squared_delta # dx_squared_delta -= 2 # filllist.sort() # print %.2f %r % (radius, filllist) # if __name__ == __main__: # octant(3.99) # octant(4) # octant(4.01) # octant(3.60) # octant(3.61) # octant(0.01) # octant(0) -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
[Michael Tobis] Also, with this code, you are using radius for the dimensions of the enclosing box, as well as the radius of the circle, so it's guaranteed to not to actually produce a whole circle. Recall what python does with negative indices! [Pythor] I'm not sure what you mean here. It produces an eighth-circle, and then plots each point in the 8 symmetrical positions on the circle. Except for the (dx+1) point made above, what piece of the circle is missing? == What Michael means is that for example a circle of radius 5 is 11 pixels wide and 11 pixels high. You are trying to cram it into a box of 5 x 5 pixels [or maybe 6x6 (I'm numpy-challenged)]. The result will resemble a train smash. Have you considered *TESTING* your code? It's not very difficult at all to draw the expected results for radii of about 4 or 5 pixels on the back of an envelope ... By the way, there are signs of a benchmark war breaking out. What are typical sizes you would be using in practice for the radius and the enclosing box? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Pythor wrote: I wrote the following code for a personal project. I need a function that will plot a filled circle in a two dimensional array. I found Bresenham's algorithm, and produced this code. Please tell me there's a better way to do this. import numpy def circle(field=None,radius,center=(0,0),value=255,): ... Break this code into two functions. Roughly: def wedge_nz(radius): '''points in octant 2 of 0-origin radius-sized circle, no zeroes''' x, y = int(radius), 1 dr2 = x ** 2 + y ** 2 r2 = radius ** 2 dy_limit = int(radius * .71) # sin of 45 degrees + a smidge while y = dy_limit: if r2 = dr2: # dx**2 + dy**2 for tx in range(1, x + 1): yield tx, y dr2 += y * 2 + 1 # dr2 = x ** 2 + (y + 1) ** 2 y += 1 else: dr2 -= x * 2 - 1 # dr2 = (x - 1) ** 2 + y ** 2 x -= 1 if x y: break and: def circle2(field=None, radius=3.2, center=(0, 0), entry=255): '''Fill field at all points within 'radius' of center with entry. center is assumed integral. ''' x, y = center if field is None: field = numpy.zeros((int(x + radius), int(y + radius)), 'u') for px, py in wedge_nz(radius): for dx in (px, -px): for dy in (py, -py): # Done once per quadrant. Do both octants. field[max(0, y + dy)][max(0, x + dx)] = entry field[max(0, y + dx)][max(0, x + dy)] = entry # do the diameters for dx in range(-radius, radius + 1): field[y][max(0, x + dx)] = entry field[max(0, y + dx)][x] = entry return field There is still overlap done at x = y and x = -y; you could squeeze that out as well by changing wedge_nz not to put it out, and making circle2 do diagonal diameters as well (leaving the center the sole overwrite). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list