Re: Python and Lotus Notes
thank you Graham Now I know how to get it thru And i have last question is it possible send mail from Lotus via Python/COM? Once Again Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
Steven D'Aprano wrote: > Mike Meyer wrote: >>BSD as well. The key word is "one". While network events don't make a >>good source of random data, proplery combining such sources can create >>good random data. > > > > Depends on what you mean by "random". In particular, > the randomness of network events does not follow a > uniform distribution, but then not many things do. > Uniformly distributed random data is what you want for > cryptography. If you are modelling physical events, you > might want some other distribution, e.g. normal (bell > curve), Poisson, exponential, binomial, geometric, > hypergeometric, and so forth. > > I have no idea what distribution data from the Internet > would have, I would imagine it is *extremely* > non-uniform and *very* biased towards certain values > (lots of "<" and ">" I bet, and relatively few "\x03"). > But, for the sake of the argument, if that's the random > distribution that you actually need, then the Internet > would be a good source of randomness. No, it works just fine as a source of randomness. It does not work as a stream of uniform random bytes, which is a different thing altogether (and to be fair, Mike made that distinction fairly clearly). It's perfectly good as one of many sources to draw on to rekey a cryptographically strong PRNG, though. C.f. http://en.wikipedia.org/wiki/Fortuna_(PRNG) -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I run python interactively?
try something like -> s = raw_input("Please Press a button...") #s is the string they type. Although i believe i remember a PEP that said they were removing raw_input so perhaps print "Please Press A button..." s = sys.stdin.readline() would be better, note the above requires you to 'import sys' -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I run python interactively?
Thanks guys for the reply. This is very helpful -- http://mail.python.org/mailman/listinfo/python-list
Re: Pychecker Re: Nested List Question
Roman Suzi <[EMAIL PROTECTED]> writes: > On Thu, 3 Nov 2005, Chris McCoy wrote: >>> gridSystemId = [[None]*columns]*rows >> You've made gridSystemID a list of `rows` references to the SAME "inner" >> list, so the behavior you observe is the only possible one. >> If you want copies instead, ASK for copies...: >> gridSystemId = [ [None]*columns for x in xrange(rows) ] > Interesting, could not pychecker recognize such situations in Python > code and give warnings? Well, it could always just issue warnings everytime it saw a list multiplied by something. But that would get annoying in the cases where that idiom doesn't have problems - which is naturally most such usages. Your example included one such, which is why the translation wasn't to: gridSystemId = [[None for y in xrange(columns)] for x in xrange(rows)] WRONG [None] * columns doesn't have problems. Nor does any other immutable object. So to avoid spurious warnings, pychecker would have to know whether the objects in the list were immutable or not. It could guess that if the objects are builtin types, but not for other types. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested List Question
"Newsfeeds" <[EMAIL PROTECTED]> wrote: > Could anyone tell me why this code produces the output it does? http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list has the full story. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pychecker Re: Nested List Question
It may, but I haven't been using Pychecker yet. I'm still fairly new to Python. Thanks, Chris M. "Roman Suzi" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 3 Nov 2005, Chris McCoy wrote: > >> Thank you! I've been banging my head against the wall! >> >> Chris M. > >>> gridSystemId = [[None]*columns]*rows >> >> You've made gridSystemID a list of `rows` references to the SAME "inner" >> list, so the behavior you observe is the only possible one. >> >> If you want copies instead, ASK for copies...: >> >> gridSystemId = [ [None]*columns for x in xrange(rows) ] > > > Interesting, could not pychecker recognize such situations in Python > code and give warnings? > > > Sincerely yours, Roman Suzi > -- > [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 > == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a blog system with Python
Are you fresh to Python or just to this group? There are quite a few python frameworks that provide functionality for blogs. You'll just have to decide which one you want to try out. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I run python interactively?
You could use either: s = raw_input("Please Hit a Key...") s being the string they typed before hitting enter. or you could use print "Please hit a key..." s = sys.stdin.readline() the only reason i recommend the second is because i believe i saw in a PEP that raw_input was being depreciated at some point, however i may be wrong on that. (correction anyone?) -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
Mike Meyer wrote: > Grant Edwards <[EMAIL PROTECTED]> writes: > >>On 2005-11-02, Neil Schemenauer <[EMAIL PROTECTED]> wrote: >> >>>Grant Edwards <[EMAIL PROTECTED]> wrote: >>>Using data from the Internet is just a bad idea. >> >>I think that the timing of certain network events is one of the >>Linux kernel's entropy sources. > > > BSD as well. The key word is "one". While network events don't make a > good source of random data, proplery combining such sources can create > good random data. Depends on what you mean by "random". In particular, the randomness of network events does not follow a uniform distribution, but then not many things do. Uniformly distributed random data is what you want for cryptography. If you are modelling physical events, you might want some other distribution, e.g. normal (bell curve), Poisson, exponential, binomial, geometric, hypergeometric, and so forth. I have no idea what distribution data from the Internet would have, I would imagine it is *extremely* non-uniform and *very* biased towards certain values (lots of "<" and ">" I bet, and relatively few "\x03"). But, for the sake of the argument, if that's the random distribution that you actually need, then the Internet would be a good source of randomness. <\pedant> Just not for encryption. It would be terrible for that. > Randomness is a deep subject. This is certainly true. I love the Dilbert cartoon where Dilbert is on a tour of Accounting. He comes across a troll sitting at a desk chanting "Nine, nine, nine, nine, ...". His guide says, "This is our random number generator." Dilbert looks skeptical and asks "Are you sure that's random?", to which the guide answers "That's the trouble with randomness, you can never be sure." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I run python interactively?
"questions?" wrote: > I need to stop the program in the middle and pause there. > > Are there anyway I can stop the program in the middle and have > something like: > > please press y to continue. portable: raw_input("please press return to continue.") to get a single character, you can use msvcrt.getch() on windows, or the termios module on unix: http://effbot.org/librarybook/msvcrt.htm http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892 http://www.faqts.com/knowledge_base/view.phtml/aid/4490/fid/538 etc -- http://mail.python.org/mailman/listinfo/python-list
Re: String Identity Test
"Richard Brodie" <[EMAIL PROTECTED]> wrote: > >"Roy Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >> On the other hand, I can't imagine any reason why you would want to >> define such a class, > >PEP 754? My congratulations on a very subtle and somewhat multicultural joke... -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows - Need to process quotes in string...
>Ernesto enlightened us with: >> >>I'm trying to use a $ delimeter, but it doesn't seem to work. Here is >>the code: >> >> >>launchWithoutConsole("devcon.exe",d'$enable >> "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&"$) Where did you get the idea that this would work? I can't find any references to a "customizable string delimiter" in any Python up through 2.4.2. I recall it being proposed at one point, but I don't think it was ever seriously considered. >> I want to send the string parameter: >> >> enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&" Sybren Stuvel <[EMAIL PROTECTED]> wrote: > >launchWithoutConsole("devcon.exe", >'enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&"') This is not correct. It might accidentally work because \V is not a defined escape sequence, but the right answer is either: launchWithoutConsole("devcon.exe", 'enable "@USB\\VID_0403&PID_6010&MI_00\\7&15E4F68&1&"') or launchWithoutConsole("devcon.exe", r'enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&"') However, devcon.exe supports regular expressions, and is forgiving about syntax. If you have only one such device, you could use: launchWithoutConsole("devcon.exe", r'enable "@USB\VID_0403&PID_6010*"') -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a function name from string
David Rasmussen wrote: > If I have a string that contains the name of a function, can I call it? > As in: > > def someFunction(): > print "Hello" > > s = "someFunction" > s() # I know this is wrong, but you get the idea... py> eval("someFunction()") 'Hello' py> eval(s)() # note the second pair of brackets 'Hello' See also exec -- but before you use either eval or exec, make sure you are fully aware of the security implications. Whatever a user could do to your system by sitting down in front of it with a Python interactive session open and typing commands at the keyboard, they can also do remotely if you call exec on input they provide. So you probably don't want to be calling exec on strings that you get from random users via a website. It has been my experience that, more often than not, any time you think you want to evaluate strings, you don't need to. For instance, instead of passing around the name of the function as a string: s = "someFunction" eval(s)() you can pass around the function as an object: s = someFunction # note the lack of brackets s() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
how can I run python interactively?
I need to stop the program in the middle and pause there. Are there anyway I can stop the program in the middle and have something like: please press y to continue. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Pychecker Re: Nested List Question
On Thu, 3 Nov 2005, Chris McCoy wrote: > Thank you! I've been banging my head against the wall! > > Chris M. >> gridSystemId = [[None]*columns]*rows > > You've made gridSystemID a list of `rows` references to the SAME "inner" > list, so the behavior you observe is the only possible one. > > If you want copies instead, ASK for copies...: > > gridSystemId = [ [None]*columns for x in xrange(rows) ] Interesting, could not pychecker recognize such situations in Python code and give warnings? Sincerely yours, Roman Suzi -- [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: XML DOM: XML/XHTML inside a text node
On Thu, 2 Nov 2005 [EMAIL PROTECTED] wrote: > In my program, I get input from the user and insert it into an XHTML > document. Sometimes, this input will contain XHTML, but since I'm > inserting it as a text node, xml.dom.minidom escapes the angle brackets > ('<' becomes '<', '>' becomes '>'). I want to be able to > override this behavior cleanly. I know I could pipe the input through > a SAX parser and create nodes to insert into the tree, but that seems > kind of messy. Is there a better way? What about parsing the input into XML first? Is there any point in including unescaped code into XML document unless it is XML itself? > Thanks. > > Sincerely yours, Roman Suzi -- [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: another beginner sort of question
John Salerno <[EMAIL PROTECTED]> writes: [Wants to learn C# and Python simultaneously.] > So my question is, is this feasible? Should be. It might be faster to do them sequentually. > Or does learning Python require (or entail) learning all the details > behind it? Not really. There are some traps you can fall into that are obvious if you know how the underlying implementation works, but even for those, you just need the general idea, not the details. > Also, do I need to know anything about C or C++? No. In fact, the less you know about them, the less you'll have to unlearn to use Python effectively. > Python seems to connected to those languages that I'm afraid > learning Python by itself might not be practical, but hopefully > that's unfounded. CPython (the implementation most people mean when they say "Python") is written in C, and has well-defined APIs for putting an interpreter into a C program, or making functionality from a C library available to a CPython program. Other implementations have similar hooks for different languages. Unless you want to get into the internals of an implementation, to embed Python in an application, or to write a Python extension (usually because you're wrapping an existing library), you won't need to worry about any of these. One thing. While Python is called a "scripting language", it doesn't have facilities for dealing with shell scripting that other "scripting languages" have. As such, it's harder to do shell scripting type things in Python than in those languages. On the other hand, it's easier than doing them in C, for the same reason that doing pretty much anything in Python is easier than doing it in C. On the gripping hand, if you do things pythonically instead of like you'd do them in a shell script, you may find that Python is easier than the shell script. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Gmane/Tunderbird users: is g.c.p.general too big?
Steve Holden wrote: > Sorry about this almost off-topic post, but I am guessing there must be > other readers of this group who use Thunderbird (in my case 1.0.2) to > access it as gmane.comp.general.python. > > I'm currently showing 344,548 articles in the group due to the gmane > policy of permanent retention, and lately it seems to have started > taking forever to switch from mailboxes to the newsgroup. Furthermore, > the Thunderbird process's memory usage climbs from ~30MB reading mail to > over 200MB reading the newsgroup. > > Has anyone else noticed this, or is it specific to my setup? Does anyone > have a solution? You can specify a policy for keeping old messages for each server account. Go to your "Account Settings" for GMane and look in "Offline & Disk Space". You can choose to keep all messages, the newest N messages, or messages from the past N days. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested List Question
Thank you! I've been banging my head against the wall! Chris M. "Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Newsfeeds <[EMAIL PROTECTED]> wrote: > >> Hello All, >> >> Could anyone tell me why this code produces the output it does? > ... >> gridSystemId = [[None]*columns]*rows > > You've made gridSystemID a list of `rows` references to the SAME "inner" > list, so the behavior you observe is the only possible one. > > If you want copies instead, ASK for copies...: > > gridSystemId = [ [None]*columns for x in xrange(rows) ] > > > Alex > == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested List Question
Newsfeeds <[EMAIL PROTECTED]> wrote: > Hello All, > > Could anyone tell me why this code produces the output it does? ... > gridSystemId = [[None]*columns]*rows You've made gridSystemID a list of `rows` references to the SAME "inner" list, so the behavior you observe is the only possible one. If you want copies instead, ASK for copies...: gridSystemId = [ [None]*columns for x in xrange(rows) ] Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: weakrefs to functions for observer pattern
Michael Schneider <[EMAIL PROTECTED]> wrote: > I would like to use weak refs in an observer pattern implementation. > The problme that I have seems to be that weakrefs can't manage functions. They can manage just fine functions written in *Python*, just not "builtin functions*, i.e., ones written in *C*. Just wrap any builtin function you need to register as observer into a tiny Python-coded wrapper and live happily ever after. ... > Not all objects can be weakly referenced; those objects which can > include class instances, functions written in Python (but not in C), Alex -- http://mail.python.org/mailman/listinfo/python-list
Nested List Question
Hello All, Could anyone tell me why this code produces the output it does? noAdjacencies = 2 gridsPerAdj = 3 rows = 4 columns = 5 gridSystemId = [[None]*columns]*rows for row in range(rows): for column in range(columns): gridSystemId[row][column] = "%d-%d" % (row,column) print gridSystemId Produces: [['3-0', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4'], ['3-0 ', '3-1', '3-2', '3-3', '3-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']] Rather than: [['0-0', '0-1', '0-2', '0-3', '0-4'], ['1-0', '1-1', '1-2', '1-3', '1-4'], ['2-0 ', '2-1', '2-2', '2-3', '2-4'], ['3-0', '3-1', '3-2', '3-3', '3-4']] Thanks for your help, Chris M. == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's website does a great disservice to the language
The Eternal Squire <[EMAIL PROTECTED]> wrote: ... > 2) Consider what he really wants for a supervisor of software > engineers. Ideally such a person should be a software engineer with > at least 3 times the experience of the most junior member. Such a I like the general idea but not your formula. If the most junior team member was 1 month out of school, would it really be OK for the supervisor to be somebody who graduated 3 months ago?-) Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for (re)try statement
Sori Schwimmer <[EMAIL PROTECTED]> wrote: ... > 2) Rocco Morreti wrote: > > What is so repugnant about the equivalent, currently > valid way of writing it? > Nothing "repugnant". We have in almost all procedural > languages an "if-else" construct, and a "case" or > "elif" as well. Python has no 'case'; 'elif' is just one of the clauses that an 'if' statement can have. > Same with "for", "while", > "do...while". Python has no 'do...while', and its for and while statements have drastically different semantics. > It's all about convenience, not about > getting to bare bone equivalents. Fattening the language up for 'convenience' is generally not the Python way. > So, I thought it's convenient to have the extra > functionality in the try statement, and am willing to > see what others think about it. My reaction is one of utter revulsion, for what it's worth. > I'm not trying to convince anybody. In the democratic > state-of-mind in which I live, the idea will be taken > in consideration if it is found useful by many, not by > one, even if the one is the almighty Guido. Not that I > don't respect his opinions, or his work on Python, but > I think that "popular demand" should prevail. Not Python did not get to its incredible success of today by basing its design decisions on "popular demand", which appears to be an even crazier notion than "design by committee". Design by a committee tends to produce a lot of bloat; design by "popular demand", i.e. a group of people substantially larger and less selected than even a committee, would no doubt produce even more bloat. If you want bloat, go use a bloated language (there are so incredibly many of them, that you'll have your pick!), and please leave alone one of the few languages that have managed to at least control the amount of cruft they have accumulated over the years (we keep hoping for a REMOVAL of many legacy features come Python 3.0 time, in fact). Alex -- http://mail.python.org/mailman/listinfo/python-list
XML DOM: XML/XHTML inside a text node
In my program, I get input from the user and insert it into an XHTML document. Sometimes, this input will contain XHTML, but since I'm inserting it as a text node, xml.dom.minidom escapes the angle brackets ('<' becomes '<', '>' becomes '>'). I want to be able to override this behavior cleanly. I know I could pipe the input through a SAX parser and create nodes to insert into the tree, but that seems kind of messy. Is there a better way? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
another beginner sort of question
Ok, like I mentioned before, I'm learning C# for fun. I'm interested in learning Python sort of as a "supplement" (by that, I mean a language with scripting capabilities that can do things maybe simpler than C# might). One concern I have about learning them simultaneously is that I'll start to get overwhelmed and mix things up, but I think I'm at least smart enough not to do that! :) My other concern is exactly how indepth I'll need to go with Python. I enjoy learning about the details of C# and the .NET Framework, but I think in order to keep things simple (in terms of learning two languages at once), I won't really get into the "behind the scenes" stuff with Python. I plan to just learn it well enough to write small scripts here and there. So my question is, is this feasible? Or does learning Python require (or entail) learning all the details behind it? Also, do I need to know anything about C or C++? Python seems to connected to those languages that I'm afraid learning Python by itself might not be practical, but hopefully that's unfounded. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Brandon K <[EMAIL PROTECTED]> wrote [inverting his topposting!]: > > Six megabytes is pretty much nothing on a modern computer. > BTW, it'd be 6 megabits or 750kb ;) ...but Mike was proposing using one digit per bit, hence, 6 megabytes. That makes it easy to search for bitpatterns with re or string.find; if the bits were packed 8 to a byte, such searches would be very hard. Alex -- http://mail.python.org/mailman/listinfo/python-list
[OT] Gmane/Tunderbird users: is g.c.p.general too big?
Sorry about this almost off-topic post, but I am guessing there must be other readers of this group who use Thunderbird (in my case 1.0.2) to access it as gmane.comp.general.python. I'm currently showing 344,548 articles in the group due to the gmane policy of permanent retention, and lately it seems to have started taking forever to switch from mailboxes to the newsgroup. Furthermore, the Thunderbird process's memory usage climbs from ~30MB reading mail to over 200MB reading the newsgroup. Has anyone else noticed this, or is it specific to my setup? Does anyone have a solution? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
hrh1818 <[EMAIL PROTECTED]> wrote: > For more information on Iron Python see http://www.ironpython.com/ > My take on Iron Python is the new job the develolper of Iron Python > started last year takes up just about all of his time and the developer > is currently spending very little time actively developing Iron Python. > I suspect it will be a long time before Iron Python will be a main > stream product. Hence I suggest you spend your time learning Python and > C# and you forget about Iron Python until it is more fully developed. According to the guy who came present IronPython at EURO OScon, there's now 1.5 people (both MS employees) working on IronPython -- the presenter himself, fulltime, and Jim Hugunin, halftime. The language is just about ready (with a few last decisions to make, such as, stick to unicode-only strings like Jython, or strive for greater practical compatibility with current CPython?); it passes the CPython unit-tests, with a few adjustments needed where the tests overspecify some aspects of behavior compared to the Language Manual. What's missing is a lot of the Python standard library -- most of the parts that are written in C in CPython (and, I believe, in Java in Jython). My impression is that the realistic timeframe to implement those is several months; meanwhile, IronPython is usable if you're willing to make direct calls to the standard MSCLR libraries (i.e., forego ease of future moves to CPython). A beginner might be best advised to stick with CPython (and, if DotNet is needed, perhaps the Python-like language Boo) while IronPython stabilizes and fleshes out, but I'm rather more optimistic than you about the speed with which that will happen. Alex -- http://mail.python.org/mailman/listinfo/python-list
weakrefs to functions for observer pattern
Hello All, I am comming back to python after being away for several years. I would like to use weak refs in an observer pattern implementation. The problme that I have seems to be that weakrefs can't manage functions. --- from docs: http://www.python.org/doc/current/lib/module-weakref.html Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), methods (both bound and unbound), sets, frozensets, file objects, generators, type objects, DBcursor objects from the bsddb module, sockets, arrays, deques, and regular expression pattern objects. Changed in version 2.4: Added support for files, sockets, arrays, and patterns. --- Is there a technique that I can use to leverage weak references to I don't have to unregister my observers? Thanks Mike PS. here is the code that I have been working with (Note: I commendout out the weak ref creation. import types class Observable(object): def addObserver(self, observer, events=None): if not hasattr(self, '_observers'): #self._observers = weakref.WeakKeyDictionary() self._observers = {} if observer is None: return if events is not None and type(events) not in (types.TupleType, types.ListType): events = (events,) self._observers[observer] = events def removeObserver(self, callable): if not hasattr(self, '_observers'): return if self._observers.has_key(callable): del self._observers[callable] ## # Notify all currently-registered Observers. # # This observer will be called if the event is one that the # Observer is interested in, or if event is 'None' # # @param event The event to notify the Observers about. None # means no specific event. # # *args - standard arguments - passed through to observer # **kw - keyword arguments - passed through to observer def notifyObservers(self, event=None, *args, **kw): if not hasattr(self, '_observers'): return for cb, events in self._observers.items(): if events is None or event is None or event in events: if cb is not None: cb(self, event, *args, **kw) -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
Grant Edwards <[EMAIL PROTECTED]> writes: > On 2005-11-02, Neil Schemenauer <[EMAIL PROTECTED]> wrote: >> Grant Edwards <[EMAIL PROTECTED]> wrote: >> Using data from the Internet is just a bad idea. > I think that the timing of certain network events is one of the > Linux kernel's entropy sources. BSD as well. The key word is "one". While network events don't make a good source of random data, proplery combining such sources can create good random data. Randomness is a deep subject. You should use a library built by experts (and appropriate for your application) rather than try and build one yourself. Most modern Unix systems have a /dev/random that qualifies for a lot of applications. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Running autogenerated code in another python instance
On Wed, 02 Nov 2005 06:33:28 +, Bengt Richter wrote: > On Wed, 2 Nov 2005 06:08:22 + (UTC), Paul Cochrane <[EMAIL PROTECTED]> > wrote: > >>Hi all, >> >>I've got an application that I'm writing that autogenerates python code >>which I then execute with exec(). I know that this is not the best way to >>run things, and I'm not 100% sure as to what I really should do. I've had a >>look through Programming Python and the Python Cookbook, which have given me >>ideas, but nothing has gelled yet, so I thought I'd put the question to the >>community. But first, let me be a little more detailed in what I want to >>do: >> Bengt, Thanks for your reply! > It's a little hard to tell without knowing more about your > user input (command language?) syntax that is translated to > or feeds the process that "autogenerates python code". Ok, I'll try and clarify things as much as I can. > E.g., is it a limited python subset that you are accepting as input, > or a command language that you might implement using the cmd module, or ? It's basically just a command language I guess. Perhaps it's best to explain using an example. Here's the pyvisi code that generates a very simple line plot using the vtk renderer module: """ Example of plotting lines with pyvisi """ # set up some data to plot from Numeric import * x = arange(10, typecode=Float) y = x**2 # example code for how a user would write a script in pyvisi from pyvisi import * # base level visualisation stuff # import the objects to render the scene using the specific renderer #from pyvisi.renderers.gnuplot import * # gnuplot from pyvisi.renderers.vtk import * # vtk #from pyvisi.renderers.plplot import *# plplot # define the scene object # a Scene is a container for all of the kinds of things you want to put # into your plot for instance, images, meshes, arrow/vector/quiver plots, # contour plots, spheres etc. scene = Scene() # create a LinePlot object plot = LinePlot(scene) # add some helpful info to the plot plot.title = 'Example 2D line plot' plot.xlabel = 'x' plot.ylabel = 'x^2' plot.linestyle = 'lines' # assign some data to the plot plot.setData(x, y) # render the scene to screen scene.render(pause=True, interactive=True) # save the scene out to file ## png plot.setData(x, y) # have to do this now because we've already # render()ed the scene, will be removed in the # future scene.save(fname="simpleLinePlot.png", format=PngImage()) This code then gets translated by the pyvisi module into the vtk-python code: import vtk from Numeric import * # LinePlot.__init__() _plot = vtk.vtkXYPlotActor() _renderer = vtk.vtkRenderer() _renderWindow = vtk.vtkRenderWindow() _renderWindow.AddRenderer(_renderer) _renderWindow.SetSize(640,480) _renderer.SetBackground(1,1,1) # Renderer._initRendererModule # LinePlot.setData() _x = array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) _xData = vtk.vtkDataArray.CreateDataArray(vtk.VTK_FLOAT) _xData.SetNumberOfTuples(len(_x)) _y0 = array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0]) _y0Data = vtk.vtkDataArray.CreateDataArray(vtk.VTK_FLOAT) _y0Data.SetNumberOfTuples(len(_y0)) for i in range(len(_x)): _xData.SetTuple1(i,_x[i]) for i in range(len(_x)): _y0Data.SetTuple1(i,_y0[i]) _fieldData0 = vtk.vtkFieldData() _fieldData0.AllocateArrays(2) _fieldData0.AddArray(_xData) _fieldData0.AddArray(_y0Data) _dataObject0 = vtk.vtkDataObject() _dataObject0.SetFieldData(_fieldData0) _plot.AddDataObjectInput(_dataObject0) _plot.SetXValuesToValue() _plot.SetDataObjectXComponent(0,0) _plot.SetDataObjectYComponent(0,1) _plot.GetXAxisActor2D().GetProperty().SetColor(0, 0, 0) _plot.GetYAxisActor2D().GetProperty().SetColor(0, 0, 0) _renderer.SetBackground(1.0, 1.0, 1.0) _lut = vtk.vtkLookupTable() _lut.Build() _colours = [] _colours.append(_lut.GetColor(0)) _plot.SetPlotColor(0, _colours[0][0], _colours[0][1], _colours[0][2]) _plot.SetPosition(0.1, 0.1) _plot.SetWidth(0.8) _plot.SetHeight(0.8) # Scene.render() _lut = vtk.vtkLookupTable() _refLut = vtk.vtkLookupTable() _lut.Build() _refLut.Build() for _i in range(256): _lut.SetTableValue(_i, _refLut.GetTableValue(255-_i)) _iRenderer = vtk.vtkRenderWindowInteractor() _iRenderer.SetRenderWindow(_renderWindow) # LinePlot.render() _renderer.AddActor2D(_plot) _plot.SetTitle('Example 2D line plot') _plot.SetXTitle('x') _plot.SetYTitle('x^2') _renderWindow.Render() _iRenderer.Start() Which is pretty ugly for the user to have to get to grips with, so I'm trying to simplify the interface to the back end. I'm writing other backends so that one only needs to change one line of code to then use gnuplot or plplot as the renderer to generate the plot. Of course some renderers can do things others can't, but that's another issue... > There are lots of easy things you could do without generating and exec-ing > python code per se. I'd love to know of other options. I like the idea of generating the cod
Re: how to write a blog system with Python
ice wrote: > I am a fresh here , and I have no idea of it. > Do you have any comments? Why do you want to write your own system? There are already lots of blog programs written in Python which you could just use, or customize. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
hrh1818 wrote: > For more information on Iron Python see http://www.ironpython.com/ > My take on Iron Python is the new job the develolper of Iron Python > started last year takes up just about all of his time and the developer > is currently spending very little time actively developing Iron Python. Actually, he just stopped updating ironpython.com (a bad idea, imo) apparently. Last release was 10/13 through Microsoft, http://www.microsoft.com/downloads/details.aspx?FamilyID=c6a7fee3-6495-427f-8b1f-768a2715170c&DisplayLang=en If that link doesn't work you can just search "IronPython" on microsoft.com Brett -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
On 2005-11-02, Neil Schemenauer <[EMAIL PROTECTED]> wrote: > Grant Edwards <[EMAIL PROTECTED]> wrote: >> Doesn't your OS have an entropy-gathering RN generator built-in? > > Alternatively, if you want lots of high-quality random numbers, buy > a cheap web camera: http://www.lavarnd.org/. The thermal noise present in a CCD sensor is a good source of random bits, but I don't get what all the stuff about taking "snapshots of a physical chaotic process" has to do it. > Using data from the Internet is just a bad idea. I think that the timing of certain network events is one of the Linux kernel's entropy sources. -- Grant Edwards grante Yow! I'm shaving!! I'M at SHAVING!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: install warning
You are importing and using, directly or indirectly, the "strop" module. Here's an example from the interactive interpreter which triggers the warning: $ python2.3 Python 2.3.3 (#1, May 7 2004, 10:31:40) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import strop >>> strop.strip(" abc ") __main__:1: DeprecationWarning: strop functions are obsolete; use string methods 'abc' Most of the things in strop are now simply methods on string objects: >>> " abc ".strip() 'abc' Another way to prevent the warning from being printed is through use of the 'warnings' module, which is documented on docs.python.org. Jeff pgpyzifxJbrUA.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft Hatred FAQ
entropy wrote: > [EMAIL PROTECTED] wrote... > >>On Tue, 25 Oct 2005 16:54:13 +, John Wingate wrote: >> >> >>>Steven D'Aprano <[EMAIL PROTECTED]> wrote: >>> That would be a good guess, except that Microsoft's predatory and illegal behaviour began long before OS/2 was even planned. It began in the mid 1970s, with MS DOS. >>> >>>Nitpick: MS-DOS first appeared in 1981. >> >>[slaps head] >> >>Of course it did. > > > The first thing I ever bought of Microsoft's, in 1982 or so, was a > CP/M board for my Apple IIe. > > CP/M, whose programmers to this day defend sticking with 8-bit CPUs > because 'they can't find a 4-bit chip they like'. Yeah, there's some > desktop innovation for you. > > OS/2 1.0 was released in 1987, but the "selling" of it started in > 1985 or so by IBM and Microsoft. It was a 286 OS. Only to the extent that IBM promised a protected-mode operating system in 1984, when the PC-AT came out. > IBM seems to have had a history of squeezing out competition in the > same way Microsoft has, if I recall correctly. IBM was genuinely innovative, and did their best to provide value for money. Microsoft hasn't been able to produce anything but me-too products since the 80's. (Multiplan, Word for DOS, the QBASIC engine, early sponsorship of mouses, and the gutsy decision to morph MS-DOS 1.0, a CP/M quasi-clone, into DOS 2.0, a Unix quasi-clone, are about all I can give them credit for.) -- John W. Kennedy "Those in the seat of power oft forget their failings and seek only the obeisance of others! Thus is bad government born! Hold in your heart that you and the people are one, human beings all, and good government shall arise of its own accord! Such is the path of virtue!" -- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis) -- http://mail.python.org/mailman/listinfo/python-list
how to write a blog system with Python
I am a fresh here , and I have no idea of it. Do you have any comments? -- http://mail.python.org/mailman/listinfo/python-list
install warning
I downloaded python 2.4. When attempting to run python interpreter, I get following: warning: strop functions are obsolete; use string methods How do I correct this? Did I do install incorrectly? Thanks - John -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP submission broken?
Bryan Olson wrote: > Though I tried to submit a (pre-) PEP in the proper form through the proper > channels, it has disappeared into the ether. > > > In building a class that supports Python's slicing interface, > >http://groups.google.com/group/comp.lang.python/msg/8f35464483aa7d7b > > I encountered a Python bug, which, upon further discussion, seemed to be > a combination of a wart and a documentation error. > > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/402d770b6f503c27 > > I submitted the bug report via SourceForge; the resolution was to document > the actual behavior. Next I worked out what behavior I think would > eliminate > the wart, wrote it up as a pre-PEP, and sent it [EMAIL PROTECTED] on 27 Aug of > this year. > > I promptly received an automated response from Barry Warsaw, saying, in > part, > "I get so much email that I can't promise a personal response." I > gathered that > he is a PEP editor. I did not infer from his reply that PEP's are simply > ignored, but > this automated reply was the only response I ever received. I subscribed > to the > Python-dev list, and watched, and waited; nothing on my concern appeared. > > > One response on the comp.lang.python newsgroup noted that a popular > extention module would have difficulty maintaining consistency with my > proposed PEP. My proposal does not break how the extension currently > works, but still, that's a valid point. There are variations which do > not have > that problem, and I think I can see a course that will serve the entire > Python community. From what I can tell, We need to address fixing the > PEP process before there is any point in working on PEP's, > > > It would seem that your PEP has failed to grab the attention of the developers. Since August there have been quite a few PEP changes. What response are you expecting from the PEP editor? In this case I would suggest you might email Barry to see whether he has taken any action on the pre-PEP, or that a post to python-dev simply inquiring whether anyone has read the pre-PEP might be appropriate. In the absence of evidence to the contrary, treat this situation as accidental rather than deliberate. Two months is a long time to wait, so maybe you should have asked about this rather sooner. Volunteers don't always behave as perfect bureaucrats :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
IronPython is good if you want to bring in Python into a .NET world. Python for .NET is good if you want to bring in .NET into a Python world. As for your learning concerns, there need be none. There is really nothing to learn extra for the integration. They just work. Once you learn the .NET framework and Python, there isn't much to know additionally. While you are on topic, check out Boo. It is not the same as the ones you mentioned but you might find it interesting and useful while working with .NET if you have Python tastes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and MySQL
Thomas Bartkus wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Thomas Bartkus wrote: >> >>>Well, I'm looking at the source for the ever popular MySQLdb library. It >>>appears to be nothing but straight up Python source code. I see no > > reason > >>>why you couldn't just take these modules and put them in your own > > private > >>>directory. There is nothing secret here. >>> >> >>I have a _mysql.c as a part of my distrbution of MySQLdb. Don't you? >> > > > You made me give that library a good hard stare. > > And no - everything is enunciated in clear Python (.py) code with > corresponding (.pyc) and (.pyo). It appears we have Python source for > everything. > >FWIW: > > print MySQLdb.version_info > > (1, 2, 0, 'final', 1) > OK. I saw that my own version was (1, 0, 0, 'final', 1), so I assumed Andy's updated the package somewhat. However, downloading the source of 1.2 I see that _mysql.c still appears, and that the package's __init__.py still includes the line include _mysql My C:\Python24\Lib\site-packages directory does contain a _mylsql.pyd file. Would you like to check that we are talking about the same module? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print random strings
[EMAIL PROTECTED] writes: > Im at the end of chapter 3 of "Python Programming For The Absolute > Beginner, Michael Dawson " and he asks to make a fortune program that > displays a fortune each time its ran, and to have 5 unique fortunes. > > Whats confusing is that, he never discussed how to do this. The only > thing he talked about was using random.randrange() and I tried that > with text but it seems like its only for integers as it complains when > I put text in the argument. > > So how would I go about have 5 strings, and running a program that will > randomly pick one of those to print? > > I think he may have forgot to cover something? Well, randrange can be used to do this, but random.choice is more pythonic. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
For more information on Iron Python see http://www.ironpython.com/ My take on Iron Python is the new job the develolper of Iron Python started last year takes up just about all of his time and the developer is currently spending very little time actively developing Iron Python. I suspect it will be a long time before Iron Python will be a main stream product. Hence I suggest you spend your time learning Python and C# and you forget about Iron Python until it is more fully developed. Howard John Salerno wrote: > Hi all. I'm currently learning C#, and I'm also interested in learning > Python (all of this just for fun, mind you), so it seems like a decent > idea to want to integrate the two. But I don't quite understand the > difference between these two Python implementations and I was hoping > someone could explain. > > Does either one require learning something different than the core > Python language? With IronPython, would you actually be writing .NET > code? I know Python for .NET is treated as a true language in the CLR, > but I don't quite grasp what all this means for each language, and what > the learning process for either language would be like as a result. > > Thanks, > John -- http://mail.python.org/mailman/listinfo/python-list
PEP submission broken?
Though I tried to submit a (pre-) PEP in the proper form through the proper channels, it has disappeared into the ether. In building a class that supports Python's slicing interface, http://groups.google.com/group/comp.lang.python/msg/8f35464483aa7d7b I encountered a Python bug, which, upon further discussion, seemed to be a combination of a wart and a documentation error. http://groups.google.com/group/comp.lang.python/browse_frm/thread/402d770b6f503c27 I submitted the bug report via SourceForge; the resolution was to document the actual behavior. Next I worked out what behavior I think would eliminate the wart, wrote it up as a pre-PEP, and sent it [EMAIL PROTECTED] on 27 Aug of this year. I promptly received an automated response from Barry Warsaw, saying, in part, "I get so much email that I can't promise a personal response." I gathered that he is a PEP editor. I did not infer from his reply that PEP's are simply ignored, but this automated reply was the only response I ever received. I subscribed to the Python-dev list, and watched, and waited; nothing on my concern appeared. One response on the comp.lang.python newsgroup noted that a popular extention module would have difficulty maintaining consistency with my proposed PEP. My proposal does not break how the extension currently works, but still, that's a valid point. There are variations which do not have that problem, and I think I can see a course that will serve the entire Python community. From what I can tell, We need to address fixing the PEP process before there is any point in working on PEP's, -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich __repr__
In article <[EMAIL PROTECTED]>, Ben Finney <[EMAIL PROTECTED]> wrote: > Erik Max Francis <[EMAIL PROTECTED]> wrote: > > Ben Finney wrote: > > > If I want to implement a __repr__ that's reasonably "nice" to the > > > programmer, what's the Right Way? Are there recipes I should look > > > at? > > > > I tend to use: > > > > def __repr__(self): > > if hasattr(self, '__str__'): > > return '<%s @ 0x%x (%s)>' % (self.__class__.__name__, > > id(self), str(self)) > > else: > > return '<%s @ 0x%x>' % (self.__class__.__name__, id(self)) > > Well that just begs the question: what's a good way (or a Right Way, > if that exists) to write a __str__ for a complex class? Well, in my opinion there pretty much isn't a good way. That is, for any randomly selected complex class, there probably is no worthwhile string value, hence no good __str__. This dives off into a certain amount of controversy over what repr and str are ideally supposed to do, but I think everyone would agree that if there's an "represent object for programmer" string value, it's the repr. So the str is presumably not for the programmer, but rather for the application, and I'm just saying that for application purposes, not all objects can usefully be reduced to a string value. Meanwhile, the code above also raises some questions where str is already provided. Run it on your subclass-of-str object and give the object a value of ') hi ('. This is why containers use repr to render their contents, not str. > It could be done just by hacking __repr__ with whatever things seem > appropriate, in some ad-hoc format. Or, as I'm hoping with this > thread, there may be common practices for outputting object state from > __repr__ that are concise yet easily standardised and/or recognised. I guess the best I could suggest is to stick with the format already used by instances (<__main__.C instance at 0x71eb8>) and augment it with class-specific information. def make_repr(self, special): return '<%s instance at 0x%x: %s>' % (self.__class__.__name__, id(self), special) def __repr__(self): return self.make_repr(repr(self.my_favorite_things)) This omits the module qualifier for the class name, but arguably that's a bit of a nuisance anyway. If there's a best, common practice way to do it, I wouldn't care to pose as an expert in such things, so you have to decide for yourself. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print random strings
[EMAIL PROTECTED] writes: > Im at the end of chapter 3 of "Python Programming For The Absolute > Beginner, Michael Dawson " and he asks to make a fortune program that > displays a fortune each time its ran, and to have 5 unique fortunes. > > Whats confusing is that, he never discussed how to do this. The only > thing he talked about was using random.randrange() and I tried that > with text but it seems like its only for integers as it complains when > I put text in the argument. > > So how would I go about have 5 strings, and running a program that will > randomly pick one of those to print? > > I think he may have forgot to cover something? How about using the integer as an index to access the elements of a list? ;-) -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: computer programming
what is .tk? Turkmenistan? or is it just some arbitrary suffix. > www.javaholics.tk == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups == Get Anonymous, Uncensored, Access to West and East Coast Server Farms! == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM == -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
BTW, it'd be 6 megabits or 750kb ;) > Six megabytes is pretty much nothing on a modern computer. == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups == Get Anonymous, Uncensored, Access to West and East Coast Server Farms! == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM == -- http://mail.python.org/mailman/listinfo/python-list
How to print random strings
Im at the end of chapter 3 of "Python Programming For The Absolute Beginner, Michael Dawson " and he asks to make a fortune program that displays a fortune each time its ran, and to have 5 unique fortunes. Whats confusing is that, he never discussed how to do this. The only thing he talked about was using random.randrange() and I tried that with text but it seems like its only for integers as it complains when I put text in the argument. So how would I go about have 5 strings, and running a program that will randomly pick one of those to print? I think he may have forgot to cover something? -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's edu corner: the Journey of Foreign Characters thru Internet
So just stop talking. It's funny that you guys are having a conversations about not responding to a guys post. First of all, freedom of speech, blah blah, who cares, just let him alone. But certainly don't go on his post, reply, telling people not to reply. That's like saying EVEN THOUGH I'M doing this, YOU should not do it. JUST STOP ALREADY :-). There is of course, the option...instead of starving the troll...FEED HIM TILL HE BURSTS! == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups == Get Anonymous, Uncensored, Access to West and East Coast Server Farms! == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM == -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a function name from string
"Paul McGuire" <[EMAIL PROTECTED]> writes: > "David Rasmussen" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> If I have a string that contains the name of a function, can I call it? >> As in: >> >> def someFunction(): >> print "Hello" >> >> s = "someFunction" >> s() # I know this is wrong, but you get the idea... >> >> /David > > Lookup the function in the vars() dictionary. > def fn(x): > ... return x*x > ... vars()['fn'] > vars()['fn'](100) > 1 vars() sans arguments is just locals, meaning it won't find functions in the global name space if you use it inside a function: >>> def fn(x): ... print x ... >>> def fn2(): ... vars()['fn']('Hello') ... >>> fn2() Traceback (most recent call last): File "", line 1, in ? File "", line 2, in fn2 KeyError: 'fn' >>> Using globals() in this case will work, but then won't find functions defined in the local name space. For a lot of uses, it'd be better to build the dictionary by hand rather than relying on one of the tools that turns a namespace into a dictionary. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: An FAQ Please Respond
Hi Clinton, If I was you, I would stick for a little while with python 2.3 untill Blender 2.40 gets stable. In the meantime you can use Movable Python (python on an usb stick) to program in Python 2.4: http://www.voidspace.org.uk/python/movpy/ But I guess Blender will become stable soon. Stani -- http://pythonide.stani.be (python editor for blender) http://pythonide.stani.be/manual/html/manual.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Burrows-Wheeler (BWT) Algorithm in Python
In article <[EMAIL PROTECTED]>, "DENG" <[EMAIL PROTECTED]> wrote: > Hi, all > > I've used Python Bz2 module for times and want to kown something about > Burrows-Wheeler (BWT) algorithm, the Bz2 module is wrriten in C, is > there a version in Python too? > > BWT > http://gatekeeper.dec.com/pub/DEC/SRC/research-reports/abstracts/src-rr-124.ht > ml > Python Bz2 module > http://labix.org/python-bz2 It is perfectly possible to implement the BWT in Python. I can send you a Python implementation I wrote, if you like; but if you're interested in better understanding how the transform works, I would recommend you try writing your own implementation. It's not very difficult to do, though for large inputs you may find performance to be an issue. Mark Nelson wrote a nice user-friendly article on the BWT for the Sep. 1996 issue of Dr. Dobbs, you might have a look: http://www.dogma.net/markn/articles/bwt/bwt.htm I hope this helps you get started. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list
Re: An FAQ Please Respond
On Wednesday 02 November 2005 04:58 pm, clinton Brandt wrote: > Hey I am Learning Blender for 3D mesh design and the current Relese doesnt > recognize my python 2.4.1 it stopped at python 2.3. there alpha test of > their next release supports py 2.4 but as a noob id like to learn an a less > buggy release. so my question is can i install 2 versions of python and if i > do, does the newer version hold rank when running .py files. or should i axe > the version i have and the start with 2.3 then load 2.4 or what? thanks Yes, you can have more than one Python installed at once. The trouble is all with making sure you start the right one when you need it (so you have to be explicit). You really should ask this question on a Blender forum, though. I can recommend: http://www.elysiun.com/ -- users' forum (this is your best bet for a simple installation problem). http://www.blender.org/ -- blender site and developers' forum Since Blender embeds its own Python interpreter, there is some question as to what exactly it means by "recognizing" an installed Python. I'm guessing it only uses the library. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: lists <-> tuple
Peter Notebaert wrote: > I am new to Python and have to create an import library in C that uses > matrices. > > These matrices can be one-dimensional (vectors) or two-dimensional. If I > look in the ActivePython 2.4 documentation at data structures, then I see at > least 2 posibilities to represent them: Lists and Tuples. > > The documention doesn't give me much information on what the best choice is > for the data type to provide/return these matrices. > > So my question is, should I use lists or tuples to represent my matrices in > and why? You'll probably want to use scipy_core. It's a package designed specifically to deal with multidimensional arrays of homogeneous, (usually) numeric data. http://numeric.scipy.org -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: An FAQ Please Respond
You can certainly have more than one version loaded. You may find it easier to fall back to Python 2.3. Unless you are using 2.4 specific features, it won't cost you much. You have to mess with path, associations, etc. in Windows registry to switch between the two. -Larry Bates clinton Brandt wrote: > Hey I am Learning Blender for 3D mesh design and the current Relese > doesnt recognize my python 2.4.1 it stopped at python 2.3. there alpha > test of their next release supports py 2.4 but as a noob id like to > learn an a less buggy release. so my question is can i install 2 > versions of python and if i do, does the newer version hold rank when > running .py files. or should i axe the version i have and the start with > 2.3 then load 2.4 or what? thanks > > > -Clinton Brandt - Windows XP Laptop > > -- http://mail.python.org/mailman/listinfo/python-list
pyzeroconf on windows
Since I'm on the topic of pyzeroconf today, I might as well keep posting ;) So on to another platform... windows. Has anyone used pyzeroconf on Windows recently? It doesn't appear to work (and it isn't the 127.0.0.1 thing either). Running python Zeroconf.py gives the following: Multicast DNS Service Discovery for Python, version 0.12 1. Testing registration of a service... Registering service... Registration done. 2. Testing query of service information... Getting ZOE service: None Query done. 3. Testing query of own service... Getting self: None Query done. 4. Testing unregister of service information... Unregister done. Traceback (most recent call last): File "Zeroconf.py", line 863, in run self.readers[socket].handle_read() File "Zeroconf.py", line 906, in handle_read data, (addr, port) = self.zeroconf.socket.recvfrom(_MAX_MSG_ABSOLUTE) File "C:\Python23\lib\socket.py", line 143, in _dummy raise error(EBADF, 'Bad file descriptor') error: (9, 'Bad file descriptor') Also, note that besides the error, the query of "own service" (#3 above) also failed to detect anything. Anyone have any clues? Thought I'd ask before delving into sockets on windows thanks matt -- http://mail.python.org/mailman/listinfo/python-list
Re: lists <-> tuple
> Tuples or lists for matrix-like functionality? Use lists. Tuples are meant for small immutable sets of things that go together. Lists are more like arrays, and you can assign to one existing element if you want. One exception, is a short vector is often a tuple like (x, y, z) and you might want to multiply that vector by your matrix. You can convert a tuple to a list with list(aTuple) or back with tuple(aList.) Even better, take a look at numarray (or numpy or scipy or scipy_core.) They all have really nice matrix code and there are C APIs that let you manipulate them. Chances are they do everything you're intending to implement. Immutability example: tup = ("a", "b", "c") tup[1] = "g" Traceback (most recent call last): File "", line 1, in ? TypeError: object does not support item assignment lst = ["a", "b", "c"] lst[1] = "g" lst ['a', 'g', 'c'] -Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Tor Erik Sønvisen wrote: > Hi > > I need a time and space efficient way of storing up to 6 million bits. The most space-efficient way of storing bits is to use the bitwise operators on an array of bytes: import array class BitList(object): def __init__(self, data=None): self._data = array.array('B') self._length = 0 if data is not None: self.extend(data) def __len__(self): return self._length def __getitem__(self, index): if index < 0: index += self._length if index < 0 or index >= self._length: raise IndexError('BitList index out of range') byte_index, bit_index = divmod(index, 8) return int(bool(self._data[byte_index] & (1 << bit_index))) def __setitem__(self, index, value): if index < 0: index += self._length if index < 0 or index >= self._length: raise IndexError('BitList index out of range') byte_index, bit_index = divmod(index, 8) byte = self._data[byte_index] bitmask = 1 << bit_index byte &= ~bitmask & 0xFF if value: byte |= bitmask self._data[byte_index] = byte def __repr__(self): return 'BitList([%s])' % ', '.join(str(bit) for bit in self) def append(self, value): if not self._length % 8: self._data.append(0) self._length += 1 self[-1] = value def extend(self, values): for v in values: self.append(v) > Time efficency is more important then space efficency In that case, you're better off simply using a list of bools. > as I'm going to do searches through the bit-set. What kind of searches? -- http://mail.python.org/mailman/listinfo/python-list
RE: convert COM obj to integer
Well that looks quite nice, so I'll work that into my script. Thanks!!! That 1-tuple business was confusing me, and I was getting errors stating something about converting an object, so as you can see, I was grasping at straws. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve M Sent: Wednesday, November 02, 2005 3:56 PM To: python-list@python.org Subject: Re: convert COM obj to integer I don't know exactly what a COM object is, but those aren't them. The win32com package takes care of converting everything to Python types. The excel call returns a tuple of tuples. That is, the outer tuple is the sequence of rows, and each such row is itself a tuple with one member per column requested. Since you only request one column, it is a one-item-long tuple, also called a 1-tuple. That is demonstrated by the result of print'ing the list. By the way, you shouldn't use 'list' as a name because it is also the name of a built-in function. And it isn't a list anyway, it's a tuple. Now, each number is in fact already a primitive Python object of type float. (The asterisk is a unicode string.) So you want to convert the floats into integers, and it looks like you want to round rather than truncate. table = xlApp.ActiveWorkbook.ActiveSheet.Range("Q13:Q36") converted_values = [] for row in table: value = row[0] #get the first (and only) item in the tuple try: value = round(value) except TypeError: #value is not a float value = None else: value = int(value) #turn the float into an int converted_values.append(value) print converted_values By the way, if you wonder how I knew to catch the TypeError, I just fired up the interactive Python interpreter, and typed this: round(u'*') -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
Grant Edwards <[EMAIL PROTECTED]> wrote: > Doesn't your OS have an entropy-gathering RN generator built-in? Alternatively, if you want lots of high-quality random numbers, buy a cheap web camera: http://www.lavarnd.org/ . Using data from the Internet is just a bad idea. Neil -- http://mail.python.org/mailman/listinfo/python-list
lists <-> tuple
I am new to Python and have to create an import library in C that uses matrices. These matrices can be one-dimensional (vectors) or two-dimensional. If I look in the ActivePython 2.4 documentation at data structures, then I see at least 2 posibilities to represent them: Lists and Tuples. The documention doesn't give me much information on what the best choice is for the data type to provide/return these matrices. So my question is, should I use lists or tuples to represent my matrices in and why? Thanks for any reaction. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and MySQL
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thomas Bartkus wrote: > > Well, I'm looking at the source for the ever popular MySQLdb library. It > > appears to be nothing but straight up Python source code. I see no reason > > why you couldn't just take these modules and put them in your own private > > directory. There is nothing secret here. > > > I have a _mysql.c as a part of my distrbution of MySQLdb. Don't you? > You made me give that library a good hard stare. And no - everything is enunciated in clear Python (.py) code with corresponding (.pyc) and (.pyo). It appears we have Python source for everything. FWIW: >>> print MySQLdb.version_info (1, 2, 0, 'final', 1) There doesn't seem to be .c code to be found anywhere. Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a function name from string
"David Rasmussen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I have a string that contains the name of a function, can I call it? > As in: > > def someFunction(): > print "Hello" > > s = "someFunction" > s() # I know this is wrong, but you get the idea... > > /David Lookup the function in the vars() dictionary. >>> def fn(x): ... return x*x ... >>> vars()['fn'] >>> vars()['fn'](100) 1 -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: convert COM obj to integer
I don't know exactly what a COM object is, but those aren't them. The win32com package takes care of converting everything to Python types. The excel call returns a tuple of tuples. That is, the outer tuple is the sequence of rows, and each such row is itself a tuple with one member per column requested. Since you only request one column, it is a one-item-long tuple, also called a 1-tuple. That is demonstrated by the result of print'ing the list. By the way, you shouldn't use 'list' as a name because it is also the name of a built-in function. And it isn't a list anyway, it's a tuple. Now, each number is in fact already a primitive Python object of type float. (The asterisk is a unicode string.) So you want to convert the floats into integers, and it looks like you want to round rather than truncate. table = xlApp.ActiveWorkbook.ActiveSheet.Range("Q13:Q36") converted_values = [] for row in table: value = row[0] #get the first (and only) item in the tuple try: value = round(value) except TypeError: #value is not a float value = None else: value = int(value) #turn the float into an int converted_values.append(value) print converted_values By the way, if you wonder how I knew to catch the TypeError, I just fired up the interactive Python interpreter, and typed this: round(u'*') -- http://mail.python.org/mailman/listinfo/python-list
Getting a function name from string
If I have a string that contains the name of a function, can I call it? As in: def someFunction(): print "Hello" s = "someFunction" s() # I know this is wrong, but you get the idea... /David -- http://mail.python.org/mailman/listinfo/python-list
An FAQ Please Respond
Hey I am Learning Blender for 3D mesh design and the current Relese doesnt recognize my python 2.4.1 it stopped at python 2.3. there alpha test of their next release supports py 2.4 but as a noob id like to learn an a less buggy release. so my question is can i install 2 versions of python and if i do, does the newer version hold rank when running .py files. or should i axe the version i have and the start with 2.3 then load 2.4 or what? thanks -Clinton Brandt - Windows XP Laptop -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
DaBeef wrote: > I have been coding for 5 years. This is a proprietary protocol, so it > is difficult converting. I did this in java but was just able to > convert a stream. What exactly did you do in Java to get the results you want? Python's library is certainly *not* "limited" in this area, so if you can describe clearly enough what you want we can certainly help. Showing an example of Java code that does the job might be a more successful way of communicating your goals to us. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
I was under the impression that IronPython is like CPython and Jython, namely an implementation of the Python language. So in that sense it is exactly like normal Python, although I don't know how convenient it is to deploy. I was also under the impression that Python for .NET is like an API wrapper thingy, analagous to the win32com package that wraps that interface and allows you to call functions and stuff provided by the .NET API. It is not at all an implementation of Python. I am confident that we will learn shortly whether I'm wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: urlencode with high characters
Jim wrote: > My understanding is that I am supposed to be able to urlencode anything > up to the top half of latin-1 -- decimal 128-255. I believe your understanding is incorrect. Without being able to quote RFCs precisely, I think your understanding should be this: - the URL literal syntax only allows for ASCII characters - bytes with no meaning in ASCII can be quoted through %hh in URLs - the precise meaning of such bytes in the URL is defined in the URL scheme, and may vary from URL scheme to URL scheme - the http scheme does not specify any interpretation of the bytes, but apparantly assumes that they denote characters, and follow some encoding - which encoding is something that the web server defines, when mapping URLs to resources. If you get the impression that this is underspecified: your impression is correct; it is underspecified indeed. There is a recent attempt to tighten the specification through IRIs. The IRI RFC defines a mapping between IRIs and URIs, and it uses UTF-8 as the encoding, not latin-1. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and MySQL
Thomas Bartkus wrote: > "Aquarius" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>I appologize in advance for this strange (and possibly stupid) >>question. >> >>I want to know if there is a way to interface a MySQL database without >>Python-MySQL or without installing anything that has C files that need >>to be compiled. The reason for this, is that I want to develop a >>certain web application, but my hosting provider ([EMAIL PROTECTED]@#%) isn't >>very >>eager to supply Python-MySQL (or any modules to python). Is there an >>alternative approach I could use to pass around this ridiculos lack of >>functionality? > > > Well, I'm looking at the source for the ever popular MySQLdb library. It > appears to be nothing but straight up Python source code. I see no reason > why you couldn't just take these modules and put them in your own private > directory. There is nothing secret here. > > But > > As others have already pointed out, after you go to this trouble, your > hosting provider will still suck! I'm sure you can you can get lot's of > suggestions for a suitable replacement. > I have a _mysql.c as a part of my distrbution of MySQLdb. Don't you? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for (re)try statement
It doesn't seem like a very useful construct, because you won't know at what point the code failed in the try block, so it could execute code at the beginning of the block several times if the error was in the middle. That could be weird. So, it would probably only be useful for one line try blocks. I wonder if you would have thought of the keyword was something other than try. For example, if it was errorcatchingblock, would you have thought of this new construct? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and MySQL
"Aquarius" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I appologize in advance for this strange (and possibly stupid) > question. > > I want to know if there is a way to interface a MySQL database without > Python-MySQL or without installing anything that has C files that need > to be compiled. The reason for this, is that I want to develop a > certain web application, but my hosting provider ([EMAIL PROTECTED]@#%) isn't > very > eager to supply Python-MySQL (or any modules to python). Is there an > alternative approach I could use to pass around this ridiculos lack of > functionality? Well, I'm looking at the source for the ever popular MySQLdb library. It appears to be nothing but straight up Python source code. I see no reason why you couldn't just take these modules and put them in your own private directory. There is nothing secret here. But As others have already pointed out, after you go to this trouble, your hosting provider will still suck! I'm sure you can you can get lot's of suggestions for a suitable replacement. Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: Retain reference to a struct
On Wed, 2005-11-02 at 16:23, [EMAIL PROTECTED] wrote: > Hi All, > > A C library I'm using has a number of functions that all require a > struct as an argument. The example module shows how to make a new > Python Object from C code and I've seen other posts that recommend this > way of doing it. > > In this case though, it would seem easier if I could create the object > in the Python code. This would require storing a pointer to an > instance of the struct until a certain function is called. > > I can get the pointer into the python code, but whenever I try to use > it to call another function, the module segfaults. Can anyone suggest > why this is? > > static PyObject * > libpyq_PQconnectdb(PyObject *self, PyObject *args) > { > PGconn *conn = PyMem_New(PGconn, sizeof(PGconn *)); > conn = (PGconn *)PQconnectdb((const char*) > PyString_AS_STRING(args)); > > printf("%p", conn); > return PyLong_FromVoidPtr(conn) ; > } > > static PyObject * > libpyq_PQfinish(PyObject *self, PyObject *args) > { > printf("%p", args); > return 1; What exactly do you think you're returning here? The function declaration says that you're supposed to return a pointer to a PyObject. '1' is not likely to be a valid pointer to anything. > } > > >>> import libpyq#works fine > >>> conn = libpyq.PQconnectdb#conn now a pointer Are you sure that's the correct example code? As written, that line doesn't call the PQconnectdb function. It assigns "conn" to be an alternate name for the PQconnectdb function. > >>> libpyq.PQfinish(conn)#segfaults That's probably due to the fact that the python interpreter wants to look up your return value for printing it, but you're returning a bogus pointer. > I'm new to C but relatively experienced with Python. I have a sneaky > suspiscion there's a good reason for not doing it this way but I > haven't seen a good explanation of why not yet. If you know one, > please tell me. The idea of passing around pointers as numbers is very unpythonic. There is no guarantee that the number that's passed into PQfinish actually came from a call to PQconnectdb. The user could pass in any integer and (probably successfully) attempt to crash the system. You should really wrap the C struct (or the pointer to the C struct) into a Python object instead. By the way, it looks like you're trying to write some sort of database access module. The 'pq' looks suspiciously like it's for PostgreSQL. If that's the case, can't you just use an existing module for connecting to PostgreSQL? HTH, Carsten Haese. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
On Wednesday 02 November 2005 12:53, DaBeef wrote: > I have been coding for 5 years. This is a proprietary protocol, so it > is difficult converting. I did this in java but was just able to > convert a stream. I looked through the Python library, I am more or > less getting backa string represented as a "" So now I want to > convert it to all the hexa, bin until I see a match and can then work > teh rest of my program Its great that you are learning python, but it seems you are confused about how it works, so you are not making sense to a lot of people. Hex conversion can be done in a lot of ways. You should look into "struct" as others have suggested, which might be a more resource effecient (less processor cycles) choice and also give you your data as numerical types. If you have managed to get to the point of having a string that looks like this: '\xcb\xdb\xbe\xef' Then the simplest thing for you to do (least amount of learning) at this point might be to look at "decode" and "encode" for example >>> hex_rep = '\xcb\xdb\xbe\xef'.encode('hex') >>> print hex_rep 'cbdbbeef' Also, you might annoy (read: 'you have annoyed') a lot of people by saying that python has a "llimited" library. Not only are you incorrect, but you made a typo. You will do well to learn as much of the python library as you can, but it will take some time. You will also do well to avoid typos and grammatical errors in your communications. Also, you need to answer Fredrik's question. Let me restate it. What do you mean by ''? This encodes in hex to '2e2e2e2e'. Is this the cipher text you were expecting? If so, your company may want to re-think its encryption algorithm. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for (re)try statement
Sori Schwimmer wrote: > 0) Sorry, I don't know how to post a reply in the same > thread. Usually it is simply hitting the "Reply" button/link/key combination on your mail/news reader when the post you want to reply to in view. (If you want reply to multiple people, you can always reply to the original post, or reply to one, and just treat the topics from all of them.) > 2) Rocco Morreti wrote: First off, let me say that my message wasn't meant to scare you off - it was constructive criticism, appraising you of what would be necessary if you actually want the construct in the language. If you're just shooting the breeze/navel gazing, I apologize for harshing your cool. >>What is so repugnant about the equivalent, currently >>valid way of writing it? > > Nothing "repugnant". "Repugnant" was probably too strong a word. The point I was trying to make was: If you want such a construct added to the language, you need to justify all the hassle & effort of introducing the new syntax. Given that there is a way to accomplish the same thing now, you would need to show that your way is not just as good, but better than the current way. > It's all about convenience, not about > getting to bare bone equivalents. Nothing wrong with convenience - you just have to show that the convenience would be used often enough to justify the hassle. It'd be awfully convenient to have a passenger jet parked in your garage - but you probably wouldn't use it frequently enough to justify the expense of maintaining, fueling, and licensing it. >> And remember - your goal isn't ultimately to >> convince me or someother >> person on comp.lang.python, it's to convince Guido > > I'm not trying to convince anybody. In the democratic > state-of-mind in which I live, the idea will be taken > in consideration if it is found useful by many, not by > one, even if the one is the almighty Guido. My comment made with the assumption that you were trying to actively promote the construct, rather than floating it as a trial balloon. I was aiming at keeping you from getting annoyed later on when your petition with hundreds of signatures gets shot down by Guido. Despite your state-of-mind, in practicality, Python is not a democracy - language constructs live or die by the will of Guido. If you actually want the construct in the language, a comp.lang.python plebiscite isn't going to do it - you'll need to convince the BDFL that it's a good idea. Now, Guido isn't totally ambivalent to the masses - if a large number of people are for it, there's a good chance Guido will be for it too. But you're not aiming for a popularity contest - what'll convince people (including Guido) is good arguments as to *why this construct is better than what we have now,* and *why it will be worth the hassle of implementing and maintaining it*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
On 2 Nov 2005 12:53:45 -0800, "DaBeef" <[EMAIL PROTECTED]> wrote: >I have been coding for 5 years. This is a proprietary protocol, so it >is difficult converting. I did this in java but was just able to >convert a stream. I looked through the Python library, I am more or >less getting backa string represented as a "" So now I want to >convert it to all the hexa, bin until I see a match and can then work >teh rest of my program > Maybe the binascii module's hexlify will get you into territory more familiar to you? Python generally stores byte data as type str "strings." If you want to see the bytes as hex (a string of hex characters ;-) you can e.g., >>> import binascii >>> binascii.hexlify('ABC123...\x01\x02\x03') '4142433132332e2e2e010203' To convert individual character, you can use a format string on the ordinal value >>> for c in 'ABC123...\x01\x02\x03': print '%02X'%ord(c), ... 41 42 43 31 32 33 2E 2E 2E 01 02 03 Or perhaps you really want the integer ordinal value itself? >>> for c in 'ABC123...\x01\x02\x03': print ord(c), ... 65 66 67 49 50 51 46 46 46 1 2 3 (print obviously does a conversion to decimal string representation for output) If you are interested in the bits, you can check them with bit operations, e.g., >>> for c in 'ABC123...\x01\x02\x03': ... print ''.join(chr(48+((ord(c)>>b)&1)) for b in xrange(7,-1,- 1)), ... 0101 0110 0111 00110001 00110010 00110011 00101110 00101110 00101110 0001 0010 0011 (cf. 41 42 42 etc above) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for .NET and IronPython
John Salerno wrote: > code? I know Python for .NET is treated as a true language in the CLR, > but I don't quite grasp what all this means for each language isn't* treated, I meant to say! -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
On Wed, 02 Nov 2005 13:55:10 +0100, Tor Erik Sønvisen wrote: > Hi > > I need a time and space efficient way of storing up to 6 million bits. [inserts pinky in corner of mouth] Six MILLION bits!!! That's almost 750K. Are you sure your computer will handle that much data? > Time > efficency is more important then space efficency as I'm going to do searches > through the bit-set. Could you be more vague if you tried? Searching for what? Does your data have structure you can exploit? Can you put it in a tree structure? Are you going to be inserting and deleting data? If you can handle your six million bits in lots of eight, store them as a character string. If you can keep your data sorted, then you can do binary searches instead of linear searches. If your data is hashable, you can store it in a dictionary and potentially get up to constant-time search speeds. Or forget about manipulating bits, and just store your data as bools in a list. Explain your problem a little better, and you may get some better advice. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
On Wed, 2 Nov 2005, Grant Edwards wrote: > On 2005-11-02, Levi Campbell <[EMAIL PROTECTED]> wrote: > >> Hi, I'm working on a random number generator using the internet as a >> way to gather entropy, I have two questions. So far interesting. >> 1. is there a way to capture the internet stream? Most news sites provide RSS and/or ATOM feeds these days. Or maybe you mean video/audio stream from Internet stations? (not sure how much entropy such a stream could contain: probably depends on the genre ;-) Or perhaps you mean low-level Ethernet/TCP/IP "stream"? Then it is not original and I already saw answers with recomendations. Sincerely yours, Roman Suzi -- [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 -- http://mail.python.org/mailman/listinfo/python-list
Retain reference to a struct
Hi All, A C library I'm using has a number of functions that all require a struct as an argument. The example module shows how to make a new Python Object from C code and I've seen other posts that recommend this way of doing it. In this case though, it would seem easier if I could create the object in the Python code. This would require storing a pointer to an instance of the struct until a certain function is called. I can get the pointer into the python code, but whenever I try to use it to call another function, the module segfaults. Can anyone suggest why this is? static PyObject * libpyq_PQconnectdb(PyObject *self, PyObject *args) { PGconn *conn = PyMem_New(PGconn, sizeof(PGconn *)); conn = (PGconn *)PQconnectdb((const char*) PyString_AS_STRING(args)); printf("%p", conn); return PyLong_FromVoidPtr(conn) ; } static PyObject * libpyq_PQfinish(PyObject *self, PyObject *args) { printf("%p", args); return 1; } >>> import libpyq#works fine >>> conn = libpyq.PQconnectdb#conn now a pointer >>> libpyq.PQfinish(conn)#segfaults I'm new to C but relatively experienced with Python. I have a sneaky suspiscion there's a good reason for not doing it this way but I haven't seen a good explanation of why not yet. If you know one, please tell me. Thanks, Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: Web automation with twill
I solved the problem by myself with the classical method of newbyes (trial and error). Bye. -- http://mail.python.org/mailman/listinfo/python-list
Python for .NET and IronPython
Hi all. I'm currently learning C#, and I'm also interested in learning Python (all of this just for fun, mind you), so it seems like a decent idea to want to integrate the two. But I don't quite understand the difference between these two Python implementations and I was hoping someone could explain. Does either one require learning something different than the core Python language? With IronPython, would you actually be writing .NET code? I know Python for .NET is treated as a true language in the CLR, but I don't quite grasp what all this means for each language, and what the learning process for either language would be like as a result. Thanks, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
On 2005-11-02, DaBeef <[EMAIL PROTECTED]> wrote: > I have been coding for 5 years. This is a proprietary protocol, so it > is difficult converting. Eh? What's so difficult about it? > I did this in java but was just able to convert a stream. Yet you seem unable to describe what it is you're trying to do. > I looked through the Python library, I am more or less getting > backa string represented as a "" And what is it you _want_? If the other end sent you four ASCII "." bytes, shouldn't that be what you see? > So now I want to convert it to all the hexa, bin Sorry, I've no clue what "hexa, bin" is or how to convert to it. > until I see a match and can then work teh rest of my program I have absolutely no idea what you're trying to do, but maybe this will help: In Python a "string" is an array of 8-bit bytes. If you want the integer equivalent of the 3rd byte in a string s, do this: b = ord(s[2]) For example: >>> s = "ABC" >>> ord(s[0]) 65 >>> ord(s[1]) 66 >>> ord(s[2]) 67 If you want a list of the integer equivalents of the bytes in a string, do this: bl = [ord(c) for c in s] >>> [ord(c) for c in s] [65, 66, 67] -- Grant Edwards grante Yow! Make me look like at LINDA RONSTADT again!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
On 2 Nov 2005 12:28:26 -0800, "DaBeef" <[EMAIL PROTECTED]> wrote: >Hello, I am reading in a socket message from a server and am only >receiving this ''. Now obviously it is in the wrong format. How >would I convert these bys in Python, I have looked everywhere but I do >not see much documentation on converting ptyhon types to other data >types. >Any Help would be appreciated. > print repr(msg) where msg is what you _actually_ read (and tell us how you got the message in, BTW) and show us a copy/pasted copy from your screen. Unless you are very very good at descriptions, it's hard to beat presentation of machine representations of what you are talking about ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: is open(...).read() a resource leak?
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Benjamin Rutt wrote: > >> If I did the following in an infinite loop, would the host system/user >> account soon run out of file descriptors? (I'm thinking no, since I'd >> imagine that a file object has a __del__-like method that will call >> close() automatically since it goes out of scope): >> >>open('/home/rutt/.bashrc,'r').read() > > under CPython, this is not a problem (the reference counting system will > make sure that file handles are reclaimed as fast as new ones are opened). It would be reclaimed immediately, correct? (As opposed to waiting for the next file-open call or some later time). In my understanding of CPython gc and reference counting, only the cyclical objects will be lazily/periodically reclaimed in a scheduled fashion, while all non-cyclical objects are reclaimed immediately when their last incoming reference decrements the count to 0. > under an arbitrary Python implementation, it may be a problem, > especially if the implementation doesn't trigger a collection if it > runs out of handles (that can be seen as a bug, though...). OK, makes sense, thank you. -- Benjamin Rutt -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
I have been coding for 5 years. This is a proprietary protocol, so it is difficult converting. I did this in java but was just able to convert a stream. I looked through the Python library, I am more or less getting backa string represented as a "" So now I want to convert it to all the hexa, bin until I see a match and can then work teh rest of my program -- http://mail.python.org/mailman/listinfo/python-list
convert COM obj to integer
I'm pulling a range of cells from Excel into a list and the data in Excel is a number or possibly some text like an asterisk. Each member of the list is a com object (I think) and I'm converting them to integers (or to None if not numberic) but my method seems very silly. Is this the best way to go about it? It does exactly what it should, but it seems like a lot of extra BS to convert my object to a string to a float to a rounded integer! Don't laugh. I'm new at this! THE SCRIPT:-- import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") f = r"C:\py\TrafficVolumes\xlTestDocs\3125113A.xls" xlApp.Visible = 0 xlApp.Workbooks.Open(f) list = xlApp.ActiveWorkbook.ActiveSheet.Range("Q13:Q36") print list print "\n" def comObjToInteger(myObj): try: s = str(myObj) fl = float(s) integer = int(round(fl)) return integer except: return None for i in list: print comObjToInteger(i) xlApp.ActiveWorkbook.Close(SaveChanges=0) xlApp.Quit() del xlApp #clean up -- THE RESULT: >>> the list: ((4.7998,), (u'*',), (2.0,), (1.6001,), (5.5996,), (19.399,), (25.0,), (38.797,), (32.797,), (21.0,), (24.0,), (17.399,), (22.801,), (22.601,), (33.797,), (35.399,), (29.199,), (35.399,), (32.203,), (26.0,), (24.399,), (22.801,), (14.0,), (11.6,)) my converted values: 5 None 2 2 6 19 25 39 33 21 24 17 23 23 34 35 29 35 32 26 24 23 14 12 -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Py2Exe produced "binary" shows terminal screen on execution
Hi, 2 Nov 2005 05:31:07 -0800, Thomas W <[EMAIL PROTECTED]>: > I've produced a "binary" version of a python-script using Py2Exe and > when run on WinXP it shows a terminal window for a brief moment then > the window disappears. How can I avoid this? I want the script to run > without being visible at all. I guess this should work: save your programm with the ending .pyw instead of .py: 'myscript.pyw'. -- Sėkmės, Kristina K. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
"DaBeef" wrote:/ > it is returning data such as 0x04. I am new to python so this is a > pain for me, learning to do this in a language whose llibrary is > somewhat limited. you make no sense at all. what are you receiving data from? how are you receiving it? what library are you using? what's 0x04? an integer? a string? a byte? what's ? a string? a typo? an odd character that's munged by your mail program? -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
DaBeef wrote: > it is returning data such as 0x04. But you need to know what kind of data the other side is sending, i.e. what kind of protocol it speaks. > I am new to python New and starting with socket/network programming ? Brave! > so this is a > pain for me, learning to do this in a language whose llibrary is > somewhat limited. You mean Pythons' library is limited? You know nothing... > >But instead I receieve So I wnat to convert to > the original data. Also can you define a constant in Python such as > #define value 0x04 You should look here: http://docs.python.org/ And probably here, too: http://diveintopython.org/toc/index.html What does your 'socket receiver' look like ? Stefan -- Stefan Näwe stefan_AT_naewe_DOT_de -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
it is returning data such as 0x04. I am new to python so this is a pain for me, learning to do this in a language whose llibrary is somewhat limited. But instead I receieve So I wnat to convert to the original data. Also can you define a constant in Python such as #define value 0x04 Thank-you for your help -- http://mail.python.org/mailman/listinfo/python-list
Re: Hexadecimal Conversion in Python
DaBeef wrote: > Hello, I am reading in a socket message from a server and am only > receiving this ''. Now obviously it is in the wrong format. How > would I convert these bys in Python, I have looked everywhere but I do > not see much documentation on converting ptyhon types to other data > types. What is the server supposed to send (you need to know that if you want to decode it). Then, lookup struct.unpack . HTH Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
On 2005-11-02, Levi Campbell <[EMAIL PROTECTED]> wrote: > Hi, I'm working on a random number generator using the internet as a > way to gather entropy, I have two questions. > > 1. is there a way to capture the internet stream? What OS? What, exactly, do you want to capture? > 2. how would I skip every 2nd, 3rd, or 4th byte to protect privacy? 2nd, 3rd, 4th, byte of what? Doesn't your OS have an entropy-gathering RN generator built-in? -- Grant Edwards grante Yow! Yow! I forgot my at PAIL!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
urlencode with high characters
Hello, I'm trying to do urllib.urlencode() with unicode correctly, and I wonder if some kind person could set me straight? My understanding is that I am supposed to be able to urlencode anything up to the top half of latin-1 -- decimal 128-255. I can't just send urlencode a unicode character: Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> s=u'abc'+unichr(246)+u'def' >>> dct={'x':s} >>> urllib.urlencode(dct) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/urllib.py", line 1206, in urlencode v = quote_plus(str(v)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 3: ordinal not in range(128) Is it instead Right that I should send a unicode string to urlencode by first encoding it to 'latin-1' ? >>> import urllib >>> s=u'abc'+unichr(246)+u'def' >>> dct={'x':s.encode('latin-1')} >>> urllib.urlencode(dct) 'x=abc%F6def' If it is Right, I'm puzzled as to why urlencode doesn't do it. Or am I missing something? urllib.ulrencode() contains the lines: elif _is_unicode(v): # is there a reasonable way to convert to ASCII? # encode generates a string, but "replace" or "ignore" # lose information and "strict" can raise UnicodeError v = quote_plus(v.encode("ASCII","replace")) l.append(k + '=' + v) so I think that it is *not* liking latin-1. Thank you, Jim -- http://mail.python.org/mailman/listinfo/python-list
Hexadecimal Conversion in Python
Hello, I am reading in a socket message from a server and am only receiving this ''. Now obviously it is in the wrong format. How would I convert these bys in Python, I have looked everywhere but I do not see much documentation on converting ptyhon types to other data types. Any Help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
SPE 0.7.5.e - Python IDE with improved uml, debugger & unicode support
What's new? SPE now creates backup files and can insert your standard signature (with for example license and copyright information) in your code. A bug that prevented SPE to start on Linux has been fixed and also a lot of bugfixes were implemented, especially for unicode. You can read more on the SPE news blog. If you like SPE, please contribute by coding, writing documentation or donating. Spread the word on blogs, ... It would be nice if some (experienced) Mac users would subscribe to the developers mailing list to speed up the Mac port for SPE. I expect my new Mac any moment. Spe is a python IDE with auto-indentation, auto completion, call tips, syntax coloring, uml viewer, syntax highlighting, class explorer, source index, auto todo list, sticky notes, integrated pycrust shell, python file browser, recent file browser, drag&drop, context help, ... Special is its blender support with a blender 3d object browser and its ability to run interactively inside blender. Spe ships with wxGlade (gui designer), PyChecker (source code doctor) and Kiki (regular expression console). Spe is extensible with wxGlade. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html -- http://mail.python.org/mailman/listinfo/python-list
Re: reading internet data to generate random numbers.
Peter Hansen wrote: >> Hi, I'm working on a random number generator using the internet as a >> way to gather entropy, I have two questions. >> >> 1. is there a way to capture the internet stream? > > What specifically do you mean by the term "internet stream" here? > Generally speaking, the internet is not "streamed" at all, but perhaps > you have some special meaning in mind that isn't in general use. maybe it's something like this he's looking for: http://sourceforge.net/projects/pylibpcap/ -- http://mail.python.org/mailman/listinfo/python-list