Fredericksburg, VA ZPUG Meeting: November 9, 7:30-9:00 PM
Please join us November 9, 7:30-9:00 PM, for the sixth meeting of the Fredericksburg, VA Zope and Python User Group (ZPUG). Squid and Zope! Using Zope for newspaper publishing! The dangers of object oriented inheritance! Free food! * Andrew Sawyers will discuss using the open source cache server Squid with Zope, including a discussion of the O'Reilly book about Squid. * Allen Schmidt, Sr. Programmer for Fredericksburg.com - the website for the Free Lance-Star - will present on Using Zope for Newspaper Publishing. * Jim Fulton, CTO of Zope Corporation, will present an abbreviated version of the argument given in Clemens Szyperski's Component Software for why both inheritance and delegation (e.g. acquisition) cause tight coupling and therefore should be avoided except in special circumstances. * We will serve delicious fruit, cheese, and soft drinks. We've had a nice group for all the meetings. Please come and bring friends! We also are now members of the O'Reilly and Apress user group programs, which gives us nice book discounts (prices better than Amazon's, for instance) and the possibility of free review copies. Ask me about details at the meeting if you are interested. General ZPUG information When: second Wednesday of every month, 7:30-9:00. Where: Zope Corporation offices. 513 Prince Edward Street; Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab). Parking: Zope Corporation parking lot; entrance on Prince Edward Street. Topics: As desired (and offered) by participants, within the constraints of having to do with Python or Zope. Contact: Gary Poster ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: String Identity Test
Hi: Were you planning to write code that relied on id(x) being different for different but identical strings x or do you just try to understand what's going on? Just try to understand what's going on. Thanks All. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's website does a great disservice to the language
On Tuesday 01 November 2005 09:45, CppNewB wrote: First comment; I hope the language is designed better than the site. The website is beautiful. I just looked. Its the logo that is a little off-putting. It makes a pretty bad first impression. Compare it to java's. Even the php logo looks better. For a real cool logo, check biopython.org. 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: wxPython: updating style of StaticText from event generated by button
I would suggest you to take a look to the wxPython custom buttons; you can find them in the demo, under Custom Controls == GenericButtons. There you will find old style buttons, that can be simple buttons or toggle buttons (with up and down states). I have XP, and they look like old style buttons. Pff. Sorry, apparently I just completely missed that specific part of the demo although I've been using the demo all the time so far. :(. This is more a wxWidgets question that a wxPython one. However, quoting the wxWidgets manual: Yes, I had looked it up in the manual, but Please note that some styles cannot be changed after the window creation [...] is hardly the same as In general you *can not* change in runtime the style of a widget. Only a very limited subset of the wxPython widgets supports style changes in runtime right ;). Thanks for the great help! - Kees -- http://mail.python.org/mailman/listinfo/python-list
Need help testing HTTP based copy commands
We have developed some Python scripts that are similar in functionality to common UNIX commands for working with files. The commands operate directly with one or several web-servers. We are new to Python programming and would therefore appreciate some feedback on the Python scripts. The documentation for the Python scripts: http://barracudaserver.com/examples/BarracudaDrive/CommandLine.html The Web-Server: http://barracudaserver.com/examples/BarracudaDrive/ Thanks, Wilfred -- http://mail.python.org/mailman/listinfo/python-list
Importing Modules
What is the best way to import all modules in a directory (and possibly a subdirectory/subdirectories), possibly including conditionals, such as regexes? -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich __repr__
Ben Finney wrote: 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? Whatever is most useful for the programmer during debugging. An idempotent __repr__ output seem to be the ideal, but as you say, there are many classes for which it's impossible. What to do in those cases? What's the Right Way? What's the common way? There is no right way. The common way is to have __str__ print something meaningful and useful. What that is for a particular class depends entirely on the circumstances. There is no uniform solution here. -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis We must all hang together, or, most assuredly, we will all hang separately. -- John Hancock -- http://mail.python.org/mailman/listinfo/python-list
expanding dictionary to function arguments
I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an argument. I cannot pass a dictionary that has more keys than the function has arguments. # Example 1 - This works: # Prints hello world! def foo (arg1='greetings', arg2='planet', arg3='.'): print arg1 + ' ' + arg2 + arg3 args = {'arg1':'hello', 'arg2':'world', 'arg3':'!'} foo (**args) # Example 2 - This does not work: # raises TypeError: foo() got an unexpected keyword argument 'arg4') def foo (arg1='greetings', arg2='planet', arg3='.'): print arg1 + ' ' + arg2 + arg3 args = {'arg1':'hello', 'arg2':'world', 'arg3':'!', 'arg4':'ignore'} foo (**args) As a practical application, I have a project where I have a config file that defines a large number of keys and values. I read the config file into a dictionary called options. I also have an API module with many functions that I want to call with arguments taken directly from the options dictionary. The key names in the options dictionary match the argument names of the functions in my API. # The ugly, brutish way: options = read_config (options.conf) extract_audio (options['source_video_filename']) compress_audio (options['audio_raw_filename'], options['audio_compressed_filename'], options['audio_sample_rate'], options['audio_bitrate']) mux (options['source_video_filename'], options['audio_compressed_filename'], options['output_video_filename']) I know that the keys in my options dictionary match the arguments of the functions in the API library, so I would like to do this: options = read_config (options.conf) extract_audio (**options) compress_audio (**options) mux (**options) I created the following function to do what I am describing. This isn't too bad, but I thought that perhaps there was some secret Python syntax that will do this for me. def apply_smart (func, args): This is similar to func(**args), but this won't complain about extra keys in 'args'. This ignores keys in 'args' that are not required by 'func'. This passes None to arguments that are not defined in 'args'. That's fine for arguments with a default valeue, but that's a bug for required arguments. I should probably raise a TypeError. if hasattr(func,'im_func'): # Handle case when func is a class method. func = func.im_func argcount = func.func_code.co_argcount required_args = dict([(k,args.get(k)) for k in func.func_code.co_varnames[:argcount]]) return func(**required_args) So, I now I can do this: options = read_config (options.conf) apply_smart (extract_audio, options) apply_smart (compress_audio, options) apply_smart (mux, options) Neat, but is that the best I can do? Yours, Noah -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's edu corner: the Journey of Foreign Characters thru Internet
Mike Meyer wrote: Xah Leh is incompetent, but apparently well-intentioned. In your view is that (well-intentioned) an established fact at this point? I was still waiting for conclusive evidence. So far the evidence appears rather strongly in favour of a verdict of true trollism, which is anything but well-intentioned. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Flat file, Python accessible database?
Karlo Lozovina wrote: [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in news:[EMAIL PROTECTED]: If you need it to be SQL-like, SQLite seems to be the right thing. Tried that one, but had some problems setting things up. On the other hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under Cygwin). I'm very curious what problems you had. In my experience SQLite requires *nothing* I'd call setup. You install Pysqlite or APSW, write your code, and it runs and works. There are no configuration steps required, nothing but creating tables (and that's a standard step with any SQL-like database). What environment were you using, and what kind of issues did you encounter? (I ask because I often recommend SQLite, but would like to temper that advice if in some cases these setup problems would cause someone trouble.) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: callback for ctypes
David Wahler wrote: Also, I can't find any references for this QImage Camera. Could you post some additional information? Trying Qimaging instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing Modules
Walter Brunswick wrote: What is the best way to import all modules in a directory (and possibly a subdirectory/subdirectories), possibly including conditionals, such as regexes? The best was, as always, depends on what your use case is. Why do you want to do this? What will you do with the modules once they are imported? Also: the second part of the question doesn't mean anything to me. What do you mean by conditionals, such as regexes, in the context of importing modules? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: expanding dictionary to function arguments
Noah a écrit : I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an argument. I cannot pass a dictionary that has more keys than the function has arguments. If you have control over the API functions declarations, makes them so: def my_api_func(arg1='', arg2='whatever', **kwargs): code_here -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's edu corner: the Journey of Foreign Characters thru Internet
Something I don't quite understand, if people think it is troll, just ignore it. What I see is that people are feeding it by commenting about either him or his post. I saw a number of threads ended up that way(like the rather long one about Microsoft). And if anyone wants to take the responsibiblity to warn the general public that it is troll so innocent readers may not be tempted into one, at least do it privately or else it is doing exactly the opposite. So it seems that there is some demand for it, withness the Microsoft thread. Peter Hansen wrote: Mike Meyer wrote: Xah Leh is incompetent, but apparently well-intentioned. In your view is that (well-intentioned) an established fact at this point? I was still waiting for conclusive evidence. So far the evidence appears rather strongly in favour of a verdict of true trollism, which is anything but well-intentioned. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Scanning a file
David Rasmussen wrote: Lasse Vågsæther Karlsen wrote: David Rasmussen wrote: snip If you must know, the above one-liner actually counts the number of frames in an MPEG2 file. I want to know this number for a number of files for various reasons. I don't want it to take forever. Don't you risk getting more frames than the file actually have? What if the encoded data happens to have the magic byte values for something else? I am not too sure about the details, but I've been told from a reliable source that 0x0100 only occurs as a begin frame marker, and not anywhere else. So far, it has been true on the files I have tried it on. Not too reliable then. 0x0100 is one of a number of unique start codes in the MPEG2 standard. It is guaranteed to be unique in the video stream, however when searching for codes within the video stream, make sure you're in the video stream! See, for example, http://forum.doom9.org/archive/index.php/t-29262.html Actually, one easy way (DVD specific) is to look for 00 00 01 e0 at byte offset 00e of the pack. Then look at byte 016, it contains the size of the extension. Resume your scan at 017 + contents of 016. Right. Glad that's the easy way. I really suspect that you need a proper MPEG2 parser, and not just blindly counting bytes -- at least if you want reliable, accurate counts and not just number of frames, plus some file-specific random number. And heaven help you if you want to support MPEGs that are slightly broken... (It has to be said, depending on your ultimate needs, close enough may very well be, um, close enough.) Good luck! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Statement Error (Tic Tac Toe)
[EMAIL PROTECTED] writes: Nevermind my previous reply: I've been fixing up the code and understand it. I'm at a nifty 80 lines where I am at now rather than 209 lines in the previous version! The changes are immense! The only problem I have is whenever player two goes, it says the cell is filled. But the code: if gameboard[cell] not in 'OX': gameboard[cell] = 'X' else: print This cell is already filled. turnnumber = turnnumber - 1 is not any different than the code I am using for player one. Anything I have to change regarding 'OX' or something else? Make sure you're setting cell properly - you didn't show that. Also, the above code is a syntax error; I assume your running code has the correct indentation. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
python CGI,sybase and environ variables
hi i am writing a CGI to process some database transactions using the Sybase module. so in my CGI script, i have: ... import Sybase import cgitb; cgitb.enable(display=1 , logdir=/tmp/weblog.txt) ... ... the problem is , everytime i have ImportError: No module named Sybase flagged out. at first i think it's library path misconfiguration, so i put os.environ[SYBASE] = '/path/to/sybase' os.environ[LD_LIBRARY_PATH] = '/path/to/sybase/lib' before i import Sybase. but its still the same error Ok.so now, is it necesary to configure the web server's nobody user's profile to point to the Sybase libraries? or worse, configure root's profile to point to Sybase libraries? what's could be wrong? thanks for any help rendered. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Statement Error (Tic Tac Toe)
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has won. At first it looked like it was working, but now it sometimes assigns a win when you enter an X or O (doesn't matter) on certain tiles (row 1, column 1 won't be an error, but row 2, column 3 will be...). If you can find the problem, I'd be very thankful! Here's the code: I see one of the reponses directs you to a web site about how to ask questions and expect answers - there's some very good advice there. Nonetheless, I'll give you the benefit of the doubt and assume that you are _very_ new to programming. I hope I haven't redone your homework for you, but if I have, I would suggest you don't submit my answer, I think it might be recognised as not being your own. The biggest problem with asking someone for help with a program like this is that it's very large (not in and of itself a problem) and, even to the most rapid glance, the program contains huge swathes of essentially the same code repeated over and over with only tiny changes. When I see that, all the warning bells start ringing. My first hint would be that anytime you find yourself typing exactly the same (or almost exactly the same thing) over and over, you are probably doing something wrong. In your original code, you have a whole section for handling player X, then you have virtually identical code, for player O. You should almost never need to do this. There are a couple of easy ways to save retyping the same code: 1) create a function. The function body will have all the identical code, the function arguments will indicate what's different between the two sections. I think this is a hint from Kernighan and Pike from a book dating back to the late 1960's - subroutines are used to show what code has in common, the arguments are used to show what's different. or 2) put the duplicated code inside a loop and let the loop variable be used to make the small changes. That's what I did in the hasty rework of your program below. Then, when we look at the code for a single player, you have 9 separate tests to see if a cell is occupied: if row == 2 and column == 1: if gameboard[3] != ('O' or 'X'): gameboard[3] = ('O') else: print This cell is already filled. turnnumber = turnnumber - 1 For each row and column, you know which cell to look at, so why have tests for every possible input, when only one test will apply for any given user input? The cell you want is: gameboard[3 * (row - 1 ) + (column - 1)] so one test can replace 9. In reworking this, I calculate this location once and save it as 'loc', since I'll be needing the location later. Then there's the question of the test if the cell is occupied: if gameboard[3] != ('O' or 'X'): This doesn't test if the cell contains an 'O' or an 'X', what it actually tests is whether the cell contains an 'O'. The reason for this is that Python sees the 'or' operator and tests if the left hand side is True, which, since it is a string, tests if the string is empty, which it isn't. Python, when given EXPR or EXPR returns the left hand EXPR if it is True, otherwise it returns the right hand expression. Also, since you know that unoccupied cells contain a space, why not test for the cell containing a space, instead of testing that it doesn't contain an 'O' and it doesn't contain an 'X'?, no 'or' operator required? If you must use 'or', then you'd have to write: if gameboard[3] == 'O' or gameboard[3] == 'X': print This cell is already filled. The next point is the entire user input section. You have a while loop waiting until the game is won, which gets the user input at the top and goes through the entire rest of the code on every user input. It's clearer to handle the user input within a smaller loop which runs forever (while 1:) prompting for input and which uses the 'break' statement to drop out of the loop when the input is valid. If I were writing this myself, I'd probably extract it into a function, simply to separate it from the game playing code. You display the current board with a very lengthy print statement, naming each cell to be printed and surrounding it with individual ']''s. But this is the sort of job computers do well. What you actually want to do is print three lines, one for board[0] through board[2], another for board[3] through board[5] and the last for board[6] through board[8]. print [%s][%s][%s] % (board[0], board[1], board[2]) etc. would work in three clearer lines, but we may as well let the computer do the calculation of the indices using a for loop. A final pair of improvements is to not type the [%s] 3 times, nor the name of the board 3 times. We can get the format string using the * n notation: '[%s]' * 3 We
Re: Problems with emulation of numeric types and coercion rules
Never mind, I forgot that class inheritance tree is a tree. Resulting type of adding Broken and Working from previous example would also depend on the order of operands. Ziga -- http://mail.python.org/mailman/listinfo/python-list
Re: If Statement Error (Tic Tac Toe)
The code's indentation was fine - I forgot to declare cell in player two's section and not just in player one. The code (including the win check, for once!) is working. The last obstacle is my tie checker; it doesn't seem to like what I have: if ((gameboard[0:9] is 'X' or 'O') and (win == 0)): print Tie. win = 2 Will the [0:9] range not work in this? Should I write out each option? Or is there some way to check if all things in the list are NOT ' '? I tried if ((gameboard[0:9] is not ' ')) but it didn't like that - once again maybe the range is the culprit. Hopefully this will be the last help I need, thanks once again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Rename files with numbers
I wrote a simpler script based in Micah Elliott's help, it's to add the band name to mp3 files imported with iTunes: import glob, os def renamer_itunes(songdir, band): Rename mp3 files imported from itunes, transformation: Song Name.mp3 -- Artists - Song Name.mp3 os.chdir(songdir) archives = glob.glob(*.mp3) pretties = [] for ugly in archives: song, ext = os.path.splitext(ugly) song = song.title() song = band + - + song songext = song + ext pretties.append(songext) for ugly, pretty in zip(archives, pretties): os.rename(ugly, pretty) Just an exercise, I'm begining in Python now... Thanks to every one that helped me, i'll bring more questions for you. Sorry for my bad english, i'm Brazilian... ! _ Eduardo Figueireredo http://dudufigueiredo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's edu corner: the Journey of Foreign Characters thru Internet
Peter Hansen [EMAIL PROTECTED] writes: Mike Meyer wrote: Xah Leh is incompetent, but apparently well-intentioned. In your view is that (well-intentioned) an established fact at this point? I was still waiting for conclusive evidence. No, it's not an established fact, which is why I said apparently. I think *he* thinks he is doing the world a favor by ignoring established netiquette in his postings. But he's clearly incompetent, and that's sufficient to explain his behavior. And there's a saying about malice and incompetence. mike -- Mike Meyer [EMAIL PROTECTED] 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: If Statement Error (Tic Tac Toe)
[EMAIL PROTECTED] writes: The code's indentation was fine - I forgot to declare cell in player two's section and not just in player one. The code (including the win check, for once!) is working. The last obstacle is my tie checker; it doesn't seem to like what I have: if ((gameboard[0:9] is 'X' or 'O') and (win == 0)): print Tie. win = 2 Will the [0:9] range not work in this? Should I write out each option? Or is there some way to check if all things in the list are NOT ' '? I tried if ((gameboard[0:9] is not ' ')) Yes, those tests are not doing what you want them to do. On the other hand, you can still test this in one swell foop with in: if ' ' not in gameboard and win == 0: print Tie. win = 2 That does assume that gameboard and gameboard[0:9] are the same thing. But they should be. For that matter, the defaults for the slice should be 0 and 9, so that gameboard[:] is the same thing yet again. But since you're not changing the board but reading it, there's no need to make a copy, which is what the sliced versions do. mike -- Mike Meyer [EMAIL PROTECTED] 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: Flat file, Python accessible database?
Karlo Lozovina wrote: I've been Googling around for _small_, flat file (no server processes), SQL-like database which can be easily access from Python. Although it doesn't support SQL queries, Metakit (http://www.equi4.com/metakit/python.html) is a very lightweight and easy to use db with a nicely pythonic API. -alex23 -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickling and unpickling inherited attributes
OK, but do be aware that slots was intended solely as a memory-conservation measure where large numbers of objects are being created. You are therefore subverting its true intent by using it to limit the assignment of extra attributes (and there has been much recent discussion on this list, though not in this thread, about what to do instead. regards Steve -- Oh, that too... We have tens of thousands of these objects in the memory at the same moment, so memory conservation is another reason for slots. -- http://mail.python.org/mailman/listinfo/python-list
Re: python CGI,sybase and environ variables
i have solved the problem. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Storing empties
Aahz [EMAIL PROTECTED] wrote: ... the canonical idiom when you need such distinction is: _not_there = object() ... What's your preferred idiom when you're dealing with storable objects? What's a storable object? You mean, something that can be pickled, or passed to the .write method of a file object, or stored in a database, or what else? Pickled and/or stored in a DB. Relational databases have the concept of NULL specifically to indicate there is NOTHING here. I love it. For pickling, object() as a unique nothing here, NOT EVEN a None marker (AKA sentinel) works fine. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Object-Relational Mapping API for Python
Aquarius wrote: I explored Java's Hibernate a bit and I was intrigued by how you can map entity objects to database tables, preserving all the relations and constraits. I am interested if there is something like this for Python - I noticed some APIs in the Cheeseshop, but most of them were alpha, better, or seemed to be forsaken a long time ago. Can you recommend me anything? SQLObject, PyDO, Durus and Django's database API. Kent -- http://mail.python.org/mailman/listinfo/python-list
dictionary that have functions with arguments
hi i have a dictionary defined as execfunc = { 'key1' : func1 } to call func1, i simply have to write execfunc[key1] . but if i have several arguments to func1 , like execfunc = { 'key1' : func1(**args) } how can i execute func1 with variable args? using eval or exec? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
[EMAIL PROTECTED] wrote: hi i have a dictionary defined as execfunc = { 'key1' : func1 } to call func1, i simply have to write execfunc[key1] . No, you ALSO have to write ( ) [[parentheses]] after that. MENTIONING a function doesn't call it, it's the parentheses that do it. but if i have several arguments to func1 , like execfunc = { 'key1' : func1(**args) } how can i execute func1 with variable args? using eval or exec? Too late: by having those parentheses there you've ALREADY called func1 at the time the execfunc dict was being built. Suggestion: parenthesise differently to make tuples: execfunc = { 'key1' : (func1, ()), 'key2' : (func2, args) } now, something like: f, a = execfunc[k] f(**a) will work for either key. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
[EMAIL PROTECTED] wrote: hi i have a dictionary defined as execfunc = { 'key1' : func1 } to call func1, i simply have to write execfunc[key1] . but if i have several arguments to func1 , like execfunc = { 'key1' : func1(**args) } how can i execute func1 with variable args? using eval or exec? thanks Eval or exec aren't needed. Normally you would just do... execfunc['key1'](**args) If your arguments are stored ahead of time with your function... execfunc = {'key1':(func1, args)} You could then do... func, args = execfunc['key1'] func(**args) Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing Modules
The purpose is rather irrelevant. The modules could be used for an assortment of tasks. By conditionals I mean if the name of a module contains a substring, such as asdf (i.e. asdf in module) or matches a pattern of some sort, for example, all modules which match the regex module[\d]+\.py, which could be module5.py or module11199.py or module345.py. -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing Modules
On the second point, a combination of sys.path, os.listdir and __import__ should do what you're after, although sifting through the whole of sys.path and subfolders from Python, rather than the interpreter itself, could be slow. (And it'll be redundant as well - __import__ will have do the same thing, though you could fix that by using the imp module). -Should- work, but not tested, so don't blame me if it doesn't: import sys, os, re def find_modules(str_pat): pat = re.compile(str_pat + '.py[co]?') init_pat = re.compile('__init__.py[co]?') for dir in sys.path: files = [n for n in os.listdir(path) if pat.search(n)] [__import__(name.rspit('.')) for name in files] for possible_dir in os.listdir(path): try: if True in [init_pat.match(n) for n in os.listdir(name + '/' + possible_dir): find_modules(str_pat) except OSError: #does os.listdir raise this? pass -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a good python module for MS SQL server
Peter Decker wrote: On 11/1/05, Jarek Zgoda [EMAIL PROTECTED] wrote: Things didn't change, as last update to adodbapi was long time ago... I had no problems with stored procedures accessed using cursor's execute() method (i.e. execute('exec sp_someproc, param')), but I never tried to get any results, just call sp and commit or rollback. Can the adodbapi module be used on a Linux/Mac client? If not, what's the best choice for cross-platform connectivity to a Microsoft SQL Server? -- # p.d. I preserved this link from a discussion about a year ago, as I may well need it one day. I have not actually tried any of the suggestions. http://groups.google.co.za/group/comp.lang.python/browse_frm/thread/bce901b08536cd89/ba6d5359c3c1b4bd Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
[EMAIL PROTECTED] writes: hi i have a dictionary defined as execfunc = { 'key1' : func1 } to call func1, i simply have to write execfunc[key1] . but if i have several arguments to func1 , like execfunc = { 'key1' : func1(**args) } how can i execute func1 with variable args? using eval or exec? Whenever you think should I use eval or exec for this, you should *immediately* stop and think What am I doing wrong?. Others have suggested using a tuple to hold the function and arguments, and pointed out the mistake in your invocation. Whenever you're thinking about doing an evalu with a fixed string, you can replace it with a lambda. That looks like: execfunc = dict(key1 = lambda: func1('hello')) def func1(x): print x ... execfunc['key1']() hello You can use the tuple format, and then use apply and the extended call syntax to keep it in one line: execfunc = dict(key1 = (func1, ('hello',))) apply(*execfunc['key1']) hello Note that applly is depreciated - you're supposed to use the extended call syntax instead. This particular use case for apply can't be handled by the extended call syntax. Using dictionaries instead of a fixed arg is a trivial change to both these examples. mike -- Mike Meyer [EMAIL PROTECTED] 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: dictionary that have functions with arguments
Ron Adam wrote: Eval or exec aren't needed. Normally you would just do... execfunc['key1'](**args) If your arguments are stored ahead of time with your function... Committed revision 41366. You could then do... func, args = execfunc['key1'] func(**args) Interesting that both Ron and Alex made the same mistake. Hmmm, makes me wonder if they are two people or not... If args is a tuple, it should be: func(*args) If you want the full generality and use keyword args: func(*args, **kwargs) kwargs would be a dictionary with string keys. E.g., execfunc = {'key1':(func1, (1,), {'keyarg': 42})} HTH, n -- http://mail.python.org/mailman/listinfo/python-list
Running autogenerated code in another python instance
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: I have a python module (called pyvisi, but you don't need to know that) which attempts to simplify the writing of scripts for high performance computing visualisation applications. What it does is provides a layer between the user and the actual renderer backend that is actually going to process the code. Effectively all my app does is to autogenerate the code the user would have to write were they savvy with the python interface to vtk (the visualisation toolkit). This reduces the effort on the part of the user quite a lot. What I have currently is my python module generating the equivalent vtk-python code and then executing this in an exec(). This is not nice (and potentially very slow), especially if one has to share around data, so what I want to do is have a separate python process or thread which just sits there accepting the autogenerated text strings as if the user were writing them directly at the python prompt (or equivalent), and returning any error messages generated. Also, I want to be able to share data between the two processes/threads so that one doesn't have to turn numerical data into a string which is then turned back into numerical data inside the exec() call (ugly, I know, but it works). Maybe a picture will help as well (time going down the page): Main Proc(1) | | Renderer(2) | | | -- Data(3) -- | | | | more commands| | --- | | | | even more cmds | | --- | | | | render finished | | shut down Rndrr | | --- | | | main proc continues or finishes (1) the main process where the python code destined for the backend is generated (2) the secondary process which accepts and runs the code it receives (3) data to visualised; shared between the two processes Ok, hopefully you get what I want to do now... So, what is the best way to do this? Threads share memory, so this is handy to share the data around, however, how does one send arbitrary commands to be processed by a thread? One way to do this would be to use pipes, but this means that I can't share the data around as easily. I've also seen the Pyro project as a possibility, but I would like to keep this as core python as possible. Any help or advice would be really (really!) appreciated. TIA Paul -- Paul Cochrane Earth Systems Science Computational Centre University of Queensland, Brisbane, Queensland 4072, Australia E: cochrane at esscc dot uq dot edu dot au -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing Modules
Sam Pointon wrote: On the second point, a combination of sys.path, os.listdir and __import__ should do what you're after, although sifting through the whole of sys.path and subfolders from Python, rather than the interpreter itself, could be slow. (And it'll be redundant as well - __import__ will have do the same thing, though you could fix that by using the imp module). -Should- work, but not tested, so don't blame me if it doesn't: [code] __import__(modulename) is not equivalent to import modulename; __import__ returns a module object __import__('pickle') module 'pickle' from 'E:\Python23\lib\pickle.py' pickle -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
Alex Martelli wrote: execfunc = { 'key1' : (func1, ()), 'key2' : (func2, args) } now, something like: f, a = execfunc[k] f(**a) will work for either key. Shouldn't func1's args be a dictionary, not a tuple? -- http://mail.python.org/mailman/listinfo/python-list
Re: Running autogenerated code in another python instance
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: [...] Any help or advice would be really (really!) appreciated. 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. 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 ? There are lots of easy things you could do without generating and exec-ing python code per se. How complex is a user session state? What modifies it? What actions are possible? History? Undo? Is the data a static passive resource to view, or partly generated or made accessible by prior actions in a session? Single user or collaborative? Shared access to everything or only to static data? Etc., etc. Some examples of user input and corresponding generated python might help, with some idea of the kind of visualization aspects being controlled ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Running autogenerated code in another python instance
Hi! I did not understand anything with your chatterer message. But, perhaps, the code below will help you. @-salutations Michel Claveau def runcode(srcode): import sys,traceback sret=True try: ccod=compile(srcode, 'Paul-code', 'exec') flagcompile=True except: print compilo-error flagcompile=False if flagcompile==True: try: exec(ccod,globals(),globals()) sret=True except: tb=sys.exc_info()[2] #for traceback print str(sys.exc_info()[0]) print traceback.format_exc() sret=False return sret s=global c a=1000 b=123 c=a+b if runcode(s): print c -- http://mail.python.org/mailman/listinfo/python-list
Re: Running autogenerated code in another python instance
With good spaces : def runcode(srcode): import sys,traceback sret=True try: ccod=compile(srcode, 'Paul-code', 'exec') flagcompile=True except: print compilo-error flagcompile=False if flagcompile==True: try: exec(ccod,globals(),globals()) sret=True except: tb=sys.exc_info()[2] #for traceback print str(sys.exc_info()[0]) print traceback.format_exc() sret=False return sret s=global c a=1000 b=123 c=a+b if runcode(s): print c s=global c a=1000 b=123 c=aaa+b if runcode(s): print c -- http://mail.python.org/mailman/listinfo/python-list
With marcos via import hooking? (Was Re: Scanning a file)
On Tue, 01 Nov 2005 07:14:57 -0600, Paul Watson [EMAIL PROTECTED] wrote: Paul Rubin wrote: [EMAIL PROTECTED] (John J. Lee) writes: Closing off this particular one would make it harder to get benefit of non-C implementations of Python, so it has been judged not worth it. I think I agree with that judgement. The right fix is PEP 343. I am sure you are right. However, PEP 343 will not change the existing body of Python source code. Nor will it, alone, change the existing body of Python programmers who are writing code which does not close files. It might be possible to recompile existing code (unchanged) to capture most typical cpython use cases, I think... E.g., I can imagine a family of command line options based on hooking import on startup and passing option info to the selected and hooked import module, which module would do extra things at the AST stage of compiling and executing modules during import, to accomplish various things. (I did a little proof of concept a while back, see http://mail.python.org/pipermail/python-list/2005-August/296594.html that gives me the feeling I could do this kind of thing). E.g., for the purposes of guaranteeing close() on files opened in typical cpython one-liners or single-suiters) like e.g. for i, line in enumerate(open(fpath)): print '%04d: %s' %(i, line.rstrip()) I think a custom import could recognize the open call in the AST and extract it and wrap it up in a try/finally AST structure implementing something like the following in the place of the above; __f = open(fpath) # (suitable algorithm for non-colliding __f names is required) try: for i, line in enumerate(__f): print '%04d: %s' %(i, line.rstrip()) finally: __f.close() In this case, the command line info passed to the special import might look like python -with open script.py meaning calls of open in a statement/suite should be recognized and extracted like __f = open(fpath) above, and the try/finally be wrapped around the use of it. I think this would capture a lot of typical usage, but of course I haven't bumped into the gotchas yet, since I haven't implemented it ;-) On a related note, I think one could implement macros of a sort in a similar way. The command line parameter would pass the name of a class which is actually extracted at AST-time, and whose methods and other class variables represent macro definitions to be used in the processing of the rest of the module's AST, before compilation per se. Thus you could implement e.g. in-lining, so that #example.py class inline: def mac(acc, x, y): acc += x*y tot = 0 for i in xrange(10): mac(tot, i*i) Could be run with python -macros inline example.py and get the same identical .pyc as you would with the source #example.py tot = 0 for i in xrange(10): tot += i*i IOW, a copy of the macro body AST is substituted for the macro call AST, with parameter names translated to actual macro call arg names. (Another variant would also permit putting the macros in a separate module, and recognize their import into other modules, and do the right thing instead of just translating the import. Maybe specify the module by python - macromodule inline example.py and then recognize import inline in example.py's AST). Again, I just have a hunch I could make this work (and a number of people here could beat me to it if they were motivated, I'm sure). Also have a hunch I might need some flame shielding. ;-) OTOH, it could be an easy way to experiment with some kinds of language tweaks. The only limitation really is the necessity for the source to look legal enough that an AST is formed and preserves the requisite info. After that, there's no limit to what an AST-munger could do, especially if it is allowed to call arbitrary tools and create auxiliary files such as e.g. .dlls for synthesized imports plugging stuff into the final translated context ;-) (I imagine this is essentially what the various machine code generating optimizers do). IMO the concept of modules and their (optionally specially controlled) translation and use could evolve in may interesting directions. E.g., __import__ could grow keyword parameters too ... Good thing there is a BDFL with a veto, eh? ;-) Should I bother trying to implement this import for with and macros from the pieces I have (plus imp, to do it right) ? BTW, I haven't experimented with command line dependent site.py/sitecustomize.py stuff. Would that be a place to do sessionwise import hooking and could one rewrite sys.argv so the special import command line opts would not be visible to subsequent processing (and the import hook would be in effect)? IWT so, but probably should read site.py again and figure it out, but appreciate any hints on pitfalls ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
Neal Norwitz wrote: Ron Adam wrote: Eval or exec aren't needed. Normally you would just do... execfunc['key1'](**args) If your arguments are stored ahead of time with your function... Committed revision 41366. Committed revision 41366 ? You could then do... func, args = execfunc['key1'] func(**args) Interesting that both Ron and Alex made the same mistake. Hmmm, makes me wonder if they are two people or not... If args is a tuple, it should be: func(*args) No mistake at all, I simply reused the name the OP used in his example. execfunc = { 'key1' : func1(**args) } There's no rule that says you can't name a dictionary 'args', and it wasn't part of the posters question. If you want the full generality and use keyword args: func(*args, **kwargs) I tend to prefer (*args, **kwds) myself. There are also times when I don't want full generality. In many cases the less general your arguments are to a function the easier it is to catch errors. Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Burrows-Wheeler (BWT) Algorithm in Python
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.html Python Bz2 module http://labix.org/python-bz2 thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Flat file, Python accessible database?
On Tue, 1 Nov 2005, Karlo Lozovina wrote: [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in news:[EMAIL PROTECTED]: If you need it to be SQL-like, SQLite seems to be the right thing. Tried that one, but had some problems setting things up. That is strange. SQLite + PySQLite are IMHO no harder to install than BerkeleyDB + Pybsddb... On the other hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under Cygwin). Sincerely yours, Roman Suzi -- [EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and DevTrack?
On 1 Nov 2005 10:57:29 -0800, warpcat [EMAIL PROTECTED] wrote: I'm a python nubie, so be gental. I've been setting up functionality by managing my Perforce clientspec with python (since it seems all of P4's commands are avaliable at the prompt), and I'd love to get access to DevTrack in the same way, but it's looking like it's off limits, UI only. Does anyone have any experience with this? Much appreciated. I have searched the posts, came up with nothing. For driving Windows GUIs, check out WATSUP. But be warned, it's a non-trivial exercise. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with py2exe
Hi Miki, I solved this first problem, thank you! I was convinced to done things you suggested me, but... it wasn't!!! I changed the access type of MSVCR71.dll and all went ok! Thank you once again for your interest, bye! P.S Thank you for your final note too, next time I'll make a better subject! Miki Tebeka wrote: Hello DDany, My guess in the MSVCR71.dll is a read-only file in system32 and when py2exe tries to copy it the 2'nd time it fails. Either change MSVCR71.dll to read-write in system32 or delete dist before calling to py2exe. One final note: You subject line could have been better, see http://www.catb.org/~esr/faqs/smart-questions.html. Bye. -- Miki Tebeka [EMAIL PROTECTED] http://tebeka.bizhat.com The only difference between children and adults is the price of the toys -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's website does a great disservice to the language
I think I'm going to back you up a little bit here. You've gone about this in a bit of a half-assed way (and pissed off a fair few people in the process) but you are right that the site needs a redesign. It uses tables for layout with inline styles and font tags and doesn't really use CSS. It has invalid html, and doesn't even attempt xhtml. From an accessiblity point of view it has a poor choice of font and a poor choice of colours (blue links on a blue background). Design issues such as what logos to use and such aren't really my forte, but from a web developers point of view it's a badly made website. Ed On 01/11/05, CppNewB [EMAIL PROTECTED] wrote: I was trying to advocate using Python for an upcoming prototype, so my boss went out to take a look at the documentation and try and get a feel for what the language is all about. First comment; I hope the language is designed better than the site. The site is readable, but is amateurish. If I had an ounce of design skills in me, I would take a stab at it. Maybe we could round up a couple of designers to donate some time? Maybe we could build a basic CMS on top of Django or TurboGears (displaying Python's capability as a web development stack)? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's edu corner: the Journey of Foreign Characters thru Internet
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... Something I don't quite understand, if people think it is troll, just ignore it. What I see is that people are feeding it by commenting about either him or his post. I saw a number of threads ended up that way(like the rather long one about Microsoft). Make it illegal to have opinions and the problem will be solved. (Oops did I break my own rule, there?) -- Svenn -- http://mail.python.org/mailman/listinfo/python-list
Re: If Statement Error (Tic Tac Toe)
[EMAIL PROTECTED] wrote: The only problem I have is whenever player two goes, it says the cell is filled. But the code: if gameboard[cell] not in 'OX': gameboard[cell] = 'X' else: print This cell is already filled. turnnumber = turnnumber - 1 is not any different than the code I am using for player one. Anything I have to change regarding 'OX' or something else? adding a print gameboard[cell] just before that if-statement is a quick way to check that the cell really contains the right thing. /F -- http://mail.python.org/mailman/listinfo/python-list
Attributes of builtin/extension objects
Hi all, I have a few questions on object introspection of builtins and extension modules. Here's an example: from datetime import date d=date(2003,1,23) d.__dict__ Traceback (most recent call last): File interactive input, line 1, in ? AttributeError: 'datetime.date' object has no attribute '__dict__' d.__slots__ Traceback (most recent call last): File interactive input, line 1, in ? AttributeError: 'datetime.date' object has no attribute '__slots__' dir(d) ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'ctime', 'day', 'fromordinal', 'fromtimestamp', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'min', 'month', 'replace', 'resolution', 'strftime', 'timetuple', 'today', 'toordinal', 'weekday', 'year'] - Where do the attributes of a datetime.date instance live if it has neither a __dict__ nor __slots__ ? - How does dir() determine them ? - dir() returns the attributes of the instance itself, its class and its ancestor classes. Is there a way to determine the attributes of the instance alone ? TIA, George -- http://mail.python.org/mailman/listinfo/python-list
Re: hello, I want to change n bytes of a binary file
Thanks to Fredrik Lundh,It works~On 11/2/05, Fredrik Lundh [EMAIL PROTECTED] wrote:could ildg wrote: so how can I do the binary stuff? 8-bit strings contain bytes. I want a encrypt function like below: def encrypt(filename,n): f = open(filename,rb+) a=f.read (n) b = encrypt(a)Thank you~~,but where is the encrypt defined?oh, I though you asked how to update the first n bytes of abinary file.if you want to XOR the bytes, you can do something like: import arrayb = array.array(B, a)for i in range(len(b)):b[i] = b[i] ^ 255b = b.tostring()orb = .join([chr(ord(c) ^ 255) for c in a]) or some variation thereof./F--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's website does a great disservice to the language
CppNewB wrote: But the logos look like they were done in Paint and maybe a readable default font is in order. I can't believe you think the font there is unreadable. It's left to the browser default, which is usually set to a simple serif font, which in turn is presumably the default because the majority of all books, magazines, and newspapers in existence use it, and have found it perfectly readable up to now. With the ability of the user to customise their font size, surely this is by definition more readable than any arbitrarily chosen typeface and size which cannot possibly suit everybody? You can append body { font-family: sans-serif; font-size: 10pt; } to the CSS and make it look 'professional' but it doesn't make it more readable. Really this just comes down to preconceptions over how a site 'should' look based on other sites, not on any tangible difference. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Python and Lotus Notes
Hello everyone. I have to get data from Lotus Notes and i curious is it possible doing it with Python. I heard that Lotus Notes using COM, so the Python does so maybe it can be done? Anyone have any experiences doing that? Ane help will by apreciated Gregor -- http://mail.python.org/mailman/listinfo/python-list
how to check for unix password
hi i created a login page that authenticate the user and his/her password to the unix ssystem. what modules can i used to compare the unix password with what the user typed in the cgi form? the password is encrypted (shadowed) so i need to decrypt it first before comparing to what the user typed. or this cannot be done at all? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: how to check for unix password
complicated issue. There is lots of authentication sub system that may be in use(PAM, LDAP, Kerberos, /etc/shadow etc.). Each has a different way. If it is linux, I think you should shoot for PAM, for other unix system I have no idea. /etc/passwd is a one way hash, you need the user submit the plain text equivalent(better use SSL) then compute and compare. However, if this is web page, I believe it would be better to use the apache2 module which has relatively good integration with the authentication system. [EMAIL PROTECTED] wrote: hi i created a login page that authenticate the user and his/her password to the unix ssystem. what modules can i used to compare the unix password with what the user typed in the cgi form? the password is encrypted (shadowed) so i need to decrypt it first before comparing to what the user typed. or this cannot be done at all? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a good python module for MS SQL server
Peter Decker napisał(a): Things didn't change, as last update to adodbapi was long time ago... I had no problems with stored procedures accessed using cursor's execute() method (i.e. execute('exec sp_someproc, param')), but I never tried to get any results, just call sp and commit or rollback. Can the adodbapi module be used on a Linux/Mac client? If not, what's the best choice for cross-platform connectivity to a Microsoft SQL Server? Nope, adodbapi relies on COM/ActiveX subsystem, so it's not available outside Windows. PyMSSQL can use DB-LIB or FreeTDS, so it may have use also on non-windows systems, see http://pymssql.sourceforge.net/ (didn't try this one, though). -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: tachometer diagram
Could it be http://xoomer.virgilio.it/infinity77/eng/freeware.html#speedmeter you are looking for? HTH Franz GEIGER Andreas Kaiser [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] Hello, I'am searching for a python solution for display a tachometer diagram. I prefer a solution for wxPython. The plot libraries I've found do not implement this diagram type. Any hints welcome! Thanks Andreas -- http://mail.python.org/mailman/listinfo/python-list
About the Python Expert
Hey, i didnt say i need an expert. wel i did... anyways, i m just saying that Fan is not a good python programmer, he doesnt know enough python to help those who have joined his group, i know its askin a lot, and i m not askin for a private tutor, just someone(s), to pop into the group, see the discussions and help the people. but it is ur decision. -- * Posted with NewsLeecher v3.0 Beta 7 * http://www.newsleecher.com/?usenet -- http://mail.python.org/mailman/listinfo/python-list
How can I setup proxy of urllib2 properly
I got some source code form python's help document. the below: proxy_handler = urllib2.ProxyHandler({'http': 'http://www.example.com:3128/'}) proxy_auth_handler = urllib2.HTTPBasicAuthHandler() proxy_auth_handler.add_password('realm', 'host', 'username', 'password') ^^^ ^ opener = urllib2.build_opener(proxy_handler, proxy_auth_handler) # This time, rather than install the OpenerDirector, we use it directly: opener.open('http://www.example.com/login.html') I have only the username and password of proxy server. But I do not know what should I provide for the 'realm' and 'host' prameters of add_password function. for example, My proxy server is www.myproxy.com username is user1 password is pass1 how can I provide parameters for add_password function? -- http://mail.python.org/mailman/listinfo/python-list
SOCKS proxy in Python?
I'm looking for a way to implement socket connections through a SOCKS (4/5) proxy in Python. I don't want to use Twisted or anything complicated - just a simple replacement for the socket library. The only thing I could find was for Python 1.0.1, and I couldn't get that to compile. Apparently it's really trivial to rewrite the socket library (a manner of a few lines) but I am not a protocol or networking guru. Can anyone help me? -- http://mail.python.org/mailman/listinfo/python-list
Re: tachometer diagram
Hi Franz, you're right! Andrea (the developer of these widgets) sends me this link about the wxPython ML. Thanks. Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: hello, I want to change n bytes of a binary file
Fredrik == Fredrik Lundh [EMAIL PROTECTED] writes: if you want to XOR the bytes, you can do something like: import array b = array.array(B, a) for i in range(len(b)): b[i] = b[i] ^ 255 b = b.tostring() or b = .join([chr(ord(c) ^ 255) for c in a]) I wish python would soon get a byte array type. For now I find numarray to be very convenient to do stuff like this. import numarray b = (numarray.array(a, type = 'u1') ^ 255).tostring() It's also significantly faster for large byte array sizes. Ganesan -- Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA Web: http://employees.org/~rganesan| http://rganesan.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Web automation with twill
Hi all, this post is a kind of continuation of my Expanding Python as a macro language Among the replies [EMAIL PROTECTED] directed me to: http://www.idyll.org/~t/www-tools/twill.html (a python tool with a language to script web commands) I applied twill to a problem I had solved by hand clicking 220 times on a button and saving the data sent by the server (it is an asp file). In this case web automation is needed! I need the help of some expert or of the author (Titus Brown). The asp file is (I am Italian!): http://www.scienzemfn.unito.it/job_placement/studenti/Elenco_completo.asp If you open it you see a button with Page Down that must be clicked to get all the data in chunks. I used twill (vers. 0.7.3) in interactive mode: twill-sh -u http://www.scienzemfn.unito.it/job_placement/studenti/Elenco_completo.asp or twill-sh ... and then go webaddress With show you see the the list of the html file representing the 1st chunk (page 1 of 223) With showforms you obtain: Form #1 ## __Name__ __Type___ __ID __Value___ PageNo hidden(None) 1 1 Mv submit(None) Page Down Form #2 ## __Name__ __Type___ __ID __Value___ PageNo hidden(None) 1 None button(None) None 1 Mv submit(None) Page Down Using twill you can access the following page and save it by: fv 1 Mv Page down submit save_html file_name with showforms you obtain: Form #1 ## __Name__ __Type___ __ID __Value___ PageNo hidden(None) 2 1 Mv submit(None) Page Down 2 Mv submit(None) Page Up Form #2 ## __Name__ __Type___ __ID __Value___ PageNo hidden(None) 2 None button(None) None 1 Mv submit(None) Page Down 2 Mv submit(None) Page Up Beeing the second page a further button shows up (Page Up) But now I get lost... I am not able to load the 3rd page... In fact repeating the aforementioned sequence: fv ... + submit the button activated by the submit command is Page Up! Any help? IMHO, twill is great ...expecially if we can make it work outside from its first use (automatic web testing). I must also say that it can be called as a module... Bye. -- http://mail.python.org/mailman/listinfo/python-list
Re: About the Python Expert
[EMAIL PROTECTED] wrote: Hey, i didnt say i need an expert. wel i did... anyways, i m just saying that Fan is not a good python programmer, he doesnt know enough python to help those who have joined his group, i know its askin a lot, and i m not askin for a private tutor, just someone(s), to pop into the group, see the discussions and help the people. but it is ur decision. Why would someone pop into the group when there are already this newsgroup and the tutor ml ? And if you are not happy with whatever group you joined, just quit. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to add thumbnails to Explorer
John J. Lee ([EMAIL PROTECTED]) wrote: : Roger Upole [EMAIL PROTECTED] writes: : Or, if not, then you can do it with module ctypes. : http://starship.python.net/crew/theller/ctypes/ : There's an O'Reilly book called something like win32 shell : programming that covers this stuff. : John Roger John - thanks for the info. Unless I'm wrong (a distinct posibility) this isn't an option, as all though COM is used as the interface, it is used to talk to *in process* code loaded from a DLL - so Python can only be used if the interpreter is invoked from within a custom shell extension .dll, which is probably not the best idea for various reasons. Thanks, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Flat file, Python accessible database?
Peter == Peter Hansen [EMAIL PROTECTED] writes: Karlo Lozovina wrote: [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in news:[EMAIL PROTECTED]: If you need it to be SQL-like, SQLite seems to be the right thing. Tried that one, but had some problems setting things up. On the other hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under Cygwin). I'm very curious what problems you had. In my experience SQLite requires *nothing* I'd call setup. You install Pysqlite or APSW, write your code, and it runs and works. I imagine that's the setup OP is talking about. You need to install it separately as opposed to bsddb. I wish SQLite is bundled with Python 2.5. To the OP, you could try gadfly (http://gadfly.sourceforge.net/gadfly.html) or KirbyBase (http://www.netpromi.com/kirbybase.html) but they are also separate packages to install. I would personally stick with SQLite. Ganesan -- Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA Web: http://employees.org/~rganesan| http://rganesan.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's website does a great disservice to the language
Ben Sizer [EMAIL PROTECTED] writes: I can't believe you think the font there is unreadable. It's left to the browser default, which is usually set to a simple serif font, which in turn is presumably the default because the majority of all books, magazines, and newspapers in existence use it, and have found it perfectly readable up to now. Actually it does set some fonts (avantgarde and lucidasomethignorother) as first choices. I guess you, like me, and probably most people in here, doesn't have those installed. -- Björn Lindström [EMAIL PROTECTED] Student of computational linguistics, Uppsala University, Sweden -- http://mail.python.org/mailman/listinfo/python-list
Most efficient way of storing 1024*1024 bits
Hi I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. regards tores -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
C ? Tor Erik Sønvisen wrote: Hi I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. regards tores -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing Modules
Walter Brunswick wrote: The purpose is rather irrelevant. The purpose of something is not only relevant but essential when someone asks for the best way to do it. For example, without knowing anything of your purpose, I could simply say that writing a module with a series of import statements, one per module in the target subdirectory, is the best way, and I could easily defend that as best against all other possible approaches until we knew what the real reason for doing this was. (Your extra detail on the regex thing makes it clear that the above approach would not be best, but I think that just goes to show that until we know why you want this, we cannot possibly answer your question properly.) -Peter -- http://mail.python.org/mailman/listinfo/python-list
* TypeError - Need help passings args
My program is below. I'm trying to use two Windows .exe files with my command line python interface. I get user input, then call launchWithoutConsole. This was working OK until I introduced the 'args' part. Now I get the following error everytime I call launchWithoutConsole: return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() TypeError: can only concatenate list (not str) to list I'm not sure if it's the WAY I'm passing it or if it's the function itself (which I retrieved from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 ) Please help. Thanks! import subprocess def launchWithoutConsole(command, args): Launches 'command' windowless and waits until finished startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() infinity = 1 #Get user input in iterative loop while infinity: userCommand = raw_input( ) if userCommand == connect: launchWithoutConsole(devcon.exe,'enable @USB\VID_0403PID_6010MI_00\715E4F681') launchWithoutConsole(devcon.exe,'enable @USB\VID_0403PID_6010MI_01\715E4F6810001') elif userCommand == disconnect: launchWithoutConsole(devcon.exe,'disable @USB\VID_0403PID_6010MI_00\715E4F681') launchWithoutConsole(devcon.exe,'disable @USB\VID_0403PID_6010MI_01\715E4F6810001') else: # include full path to rib.exe in quotes. launchWithoutConsole(rib.exe, userCommand) -- http://mail.python.org/mailman/listinfo/python-list
Py2Exe produced binary shows terminal screen on execution
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. Thanks in advance, Thomas -- http://mail.python.org/mailman/listinfo/python-list
computer programming
hello all! if u dont mind, please visit and register in my site www.javaholics.tk for java programming discussions all other programming languages and discussions are welcome! its a gr8 site and a growing community the only advantage is that its got more features as its based on SMF(Simple Machines Forum) with a advanced professional interface enjoy! remember u cant see hidden sections until you register... and thank you! -Prado. -- http://mail.python.org/mailman/listinfo/python-list
Re: About the Python Expert
On 2005-11-02, blahman ([EMAIL PROTECTED]) wrote: Hey, i didnt say i need an expert. wel i did... anyways, i m just saying that Fan is not a good python programmer, he doesnt know enough python to help those who have joined his group, They should have joined a group that _does_ contain people who know enough to help. Comp.lang.python, for example. Or the tutor mailing list. i know its askin a lot, Yes it is. As apparently is spelling and punctuation. and i m not askin for a private tutor, just someone(s), to pop into the group, see the discussions and help the people. but it is ur decision. There's _already_ a tutor mailing list and a general Python newsgroup -- both full of knowledgeable and helpful people. [Since I took a shot at this guy's spelling, there's _got_ to be a spelling error in my post, but I can't find it...] -- Grant Edwards grante Yow! I want a VEGETARIAN at BURRITO to go... with visi.comEXTRA MSG!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Tor Erik Sønvisen [EMAIL PROTECTED] writes: I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. Umm, what kind of searches do you want to do? For speed you want to use built-in functions wherever you can, string.find and that kind of thing. So choose your data format accordingly. -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary that have functions with arguments
Leif K-Brooks [EMAIL PROTECTED] wrote: Alex Martelli wrote: execfunc = { 'key1' : (func1, ()), 'key2' : (func2, args) } now, something like: f, a = execfunc[k] f(**a) will work for either key. Shouldn't func1's args be a dictionary, not a tuple? Yes, to call with ** a must be a dict (so {}, not ()). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: WTF?
[James Stroud] Why do my posts get held for suspcious headers You're probably trying to post through the python-list email address, which has had SPAM problems in the past, because the email address has been used by spammers as a forged from address, meaning the bounces would go to everyone, including being gateway'ed to comp.lang.python, which is the NNTP group in which many people read this list. Have you tried using an NNTP client instead, or using a web interface such as Google Groups? http://groups.google.com/group/comp.lang.python?gvc=2 and troll Xha Lee gets to post all sorts of profanity and ranting without any problem? Take a look at the source of XL's messages: he posts through Google Groups, thus completely avoiding the SPAM filter on python.org. http://groups.google.com/group/comp.lang.python/msg/762c8dad1928ecc2?dmode=source -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Flat file, Python accessible database?
Peter Hansen wrote: Karlo Lozovina wrote: [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in news:[EMAIL PROTECTED]: If you need it to be SQL-like, SQLite seems to be the right thing. Tried that one, but had some problems setting things up. On the other hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under Cygwin). I'm very curious what problems you had. In my experience SQLite requires *nothing* I'd call setup. You install Pysqlite or APSW, write your code, and it runs and works. There are no configuration steps required, nothing but creating tables (and that's a standard step with any SQL-like database). What environment were you using, and what kind of issues did you encounter? (I ask because I often recommend SQLite, but would like to temper that advice if in some cases these setup problems would cause someone trouble.) -Peter My experience on Cygwin was that I had to install sqlite before pySqlite worked. Maybe that's what was meant. 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's website does a great disservice to the language
Things, which can be done better are: - seperate content and layout (no table design, no font tags, ...) - blue links on blue background are nearly as ugly as visited-purple links on blue background - he frontpage is overloaded. Ok this is worth a discussion: poweruser vs. marketing -- http://mail.python.org/mailman/listinfo/python-list
Re: how to check for unix password
[EMAIL PROTECTED] writes: i created a login page that authenticate the user and his/her password to the unix ssystem. what modules can i used to compare the unix password with what the user typed in the cgi form? the password is encrypted (shadowed) so i need to decrypt it first before comparing to what the user typed. or this cannot be done at all? As has already been pointed out, users authenticate to Unix systems with a lot more than passwords. Also, it's not a good idea to make a web page use a system password. Web page passwords tend to be poorly protected. Finally, you can't decrypt a Unix password file password. The algorithm is to encrypt what the user typed (with crypt.crypt) then compare that with the entry in the password file. You pass crypt.crypt the user-entered pasword as the first argument, and the password from the password file as the second, and compare the returned value to the password from the password file. mike -- Mike Meyer [EMAIL PROTECTED] 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: Windows - Need to process quotes in string...
Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: 'super' to only be used for diamond inheritance problems?
Giovanni Bajo wrote: Alex Hunsley wrote: I've seen a few discussion about the use of 'super' in Python, including the opinion that 'super' should only be used to solve inheritance diamond problem. (And that a constructor that wants to call the superclass methods should just call them by name and forget about super.) What is people's opinion on this? Does it make any sense? I personally consider super a half-failure in Python. Some of my reasons are cited here: http://fuhm.org/super-harmful/ It would help to have some clearer guidelines on class (type) usage. I like James Knight's (fuhm) suggestion with respect to consistent signatures. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Fredericksburg, VA ZPUG Meeting: November 9, 7:30-9:00 PM
Please join us November 9, 7:30-9:00 PM, for the sixth meeting of the Fredericksburg, VA Zope and Python User Group (ZPUG). Squid and Zope! Using Zope for newspaper publishing! The dangers of object oriented inheritance! Free food! * Andrew Sawyers will discuss using the open source cache server Squid with Zope, including a discussion of the O'Reilly book about Squid. * Allen Schmidt, Sr. Programmer for Fredericksburg.com - the website for the Free Lance-Star - will present on Using Zope for Newspaper Publishing. * Jim Fulton, CTO of Zope Corporation, will present an abbreviated version of the argument given in Clemens Szyperski's Component Software for why both inheritance and delegation (e.g. acquisition) cause tight coupling and therefore should be avoided except in special circumstances. * We will serve delicious fruit, cheese, and soft drinks. We've had a nice group for all the meetings. Please come and bring friends! We also are now members of the O'Reilly and Apress user group programs, which gives us nice book discounts (prices better than Amazon's, for instance) and the possibility of free review copies. Ask me about details at the meeting if you are interested. General ZPUG information When: second Wednesday of every month, 7:30-9:00. Where: Zope Corporation offices. 513 Prince Edward Street; Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab). Parking: Zope Corporation parking lot; entrance on Prince Edward Street. Topics: As desired (and offered) by participants, within the constraints of having to do with Python or Zope. Contact: Gary Poster ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Mike Meyer [EMAIL PROTECTED] writes: Six megabytes is pretty much nothing on a modern computer. I'd store the things as a string of 0 and 1, and then use .find (or maybe the in keyword) for doing the searches. This doesn't work very well if you're going to mutate the string, though. You can use re.search on array.array byte vectors. I don't know how the speed compares with string.find. -- http://mail.python.org/mailman/listinfo/python-list
Re: Spambayes modifications with web services
Thank you for the flippant remarks. Let's just say that I found them to be unproductive. I would like to point out the process was not designed to be automatic and I don't believe made such a statement. I should clarify that my desire was to list each domain that was contained in a spam email, so that the user could then: - check if previously it has been reported as spam, or - open the link in their browser, and - check whether the domain was spam or ham, and then if spam - post it to the web service (Post Spam Site to Web Service). Therefore, thanks, yes, I did think through the consequences of my actions. The line that reads WARNING: DO NOT BUY FROM THIS WEBSITE. THE SPAMMER IS., was tongue in cheek, and it seems to be the line that stirred up the condescending comments. What I should have written was something more along the lines of: WARNING: The website domain has been reported by x users as a website that uses illegal spam email to generate business leads I think that is a perfectly useful and fair statement, which I cannot see damaging legitimate business enterprises. I also think it would be quite useful for consumers to know that the domain name they are about to purchase had previously been misused by spammers, and was quite likely to be blacklisted by spam software. I must say that I am surprised that the python group could be so unfriendly and unhelpful. Many thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Web automation with twill
You might want to post your question to the twill mailing list. Info about the list is available at http://lists.idyll.org/listinfo/twill Grig -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Tor Erik Sønvisen [EMAIL PROTECTED] writes: I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. Six megabytes is pretty much nothing on a modern computer. I'd store the things as a string of 0 and 1, and then use .find (or maybe the in keyword) for doing the searches. This doesn't work very well if you're going to mutate the string, though. mike -- Mike Meyer [EMAIL PROTECTED] 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's website does a great disservice to the language
Björn Lindström wrote: Actually it does set some fonts (avantgarde and lucidasomethignorother) as first choices. I guess you, like me, and probably most people in here, doesn't have those installed. As far as I can tell, those fonts are only set for 'pre' and 'h' tags. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: * TypeError - Need help passings args
Ernesto wrote: My program is below. I'm trying to use two Windows .exe files with my command line python interface. I get user input, then call launchWithoutConsole. This was working OK until I introduced the 'args' part. Now I get the following error everytime I call launchWithoutConsole: return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() TypeError: can only concatenate list (not str) to list I'm not sure if it's the WAY I'm passing it or if it's the function itself (which I retrieved from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 ) Please help. Thanks! [command] is a list. So also args should be a list, otherwise [command] + args produces an error. Add a few square brackets to the calls, just like in the link. -- http://mail.python.org/mailman/listinfo/python-list
Re: Py2Exe produced binary shows terminal screen on execution
Thomas W wrote: 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. You probably used the console option? See this page (http://www.py2exe.org/) for information about the alternate windows option where it says: '''The above setup script creates a console program, if you want a GUI program without the console window, simply replace console=[myscript.py] with windows=[myscript.py].''' -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Lotus Notes
Grzegorz Slusarek wrote: Hello everyone. I have to get data from Lotus Notes and i curious is it possible doing it with Python. I heard that Lotus Notes using COM, so the Python does so maybe it can be done? Anyone have any experiences doing that? Ane help will by apreciated Yes, it's pretty simple. Quick example: from win32com.client import Dispatch session = Dispatch('Lotus.NotesSession') session.Initialize(MY_NOTES_PASSWORD) db = session.getDatabase(SERVER_NAME, DB_NAME) ... The LotusScript reference guide is almost completely applicable to Notes via COM. It can be useful to define some helper functions to make working with Notes a bit easier. For example, this is the (very clunky) way to iterate all documents in a Notes database, without helper code: view = db.getView('Important Docs') doc = db.getFirstDocument() while doc: do_something_with(doc) doc = view.getNextDocument(doc) You probably recognize the pattern from any LotusScript you've written. (It sure is easy to forget that last line...) But Python gives you far better control structures, like generators. It's worthwhile to define a few helper functions like this, in a common module: def iterateDocuments(docs): doc = docs.getFirstDocument() while doc: yield doc doc = docs.getNextDocument(doc) Then you can write much cleaner code, like this: for doc in iterateDocuments(view): do_something_with(doc) Similarly you can write iterator functions for traversing databases, ACL entries, etc. I also find these two defnitions useful: def get(doc, attr): return doc.getItemValue(attr) def get1(doc, attr): return get(doc, attr)[0] because it's a lot easier to write: user_name = get1(user_doc, 'FullName') than: user_name = user_doc.getItemValue('FullName')[0] Note that the attribute-access style that LotusScript allows, e.g. user_doc.FullName(0) does not work in Python/COM, hence you'll need getItemValue(), replaceItemValue(), etc.. You could write a wrapper for the NotesDocument class that would give you attributes like this. Personally, I find that to be more trouble than it's worth, but your needs be very different. Last warning: once you've tried using Python and COM, you'll scream whenever you have to write LotusScript, and you'll wish like crazy that Notes/Domino supported Python as a native scripting language. :-) Jython kind of works, but I never got it happily running for server-side code, alas. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: MoinMoin - Can't create new pages
ferg, did you get any more replies on this, or figure it out somehow? I've got exactly the same problem with IIS5, W2K and Moin 1.3.5 - works fine except gives 404 for non-existent pages. -- http://mail.python.org/mailman/listinfo/python-list
Re: Most efficient way of storing 1024*1024 bits
Paul Rubin http://[EMAIL PROTECTED] wrote: ... You can use re.search on array.array byte vectors. I don't know how the speed compares with string.find. Pretty well, though of course one should measure on representative cases for one's specific application needs: Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=99*x' -s'x=x+a+x' \ 'x.find(a)' 100 loops, best of 3: 13.3 msec per loop Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=99*x' -s'x=x+a+x' 're.search(a, x)' 100 loops, best of 3: 8.73 msec per loop Helen:~ alex$ python -mtimeit -s'import re, array' -s'x=99*x' -s'x=x+a+x' -s'x=array.array(c,x)' 're.search(a, x)' 100 loops, best of 3: 8.72 msec per loop Alex -- http://mail.python.org/mailman/listinfo/python-list
where to download md5.py?
I've been looking around, but haven't found a place to download the md5.py module. I need it to run the dupinator.py Anyone know where to find it? Kev -- http://mail.python.org/mailman/listinfo/python-list
File renaming recipe (was: Rename files with numbers)
On Nov 01, Dudu Figueiredo wrote: I wrote a simpler script based in Micah Elliott's help... I expanded my code from this thread to be a Cookbook recipe. It has no specificity for MP3 renaming, but is generic to files with shell-unfriendly names. It should usable as-posted if anyone needs to cleanup a filesystem. Any comments/improvements are appreciated. Title: Fix ugly file names to be UNIX shell-friendly. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442517 -- _ _ ___ |V|icah |- lliott http://micah.elliott.name [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: where to download md5.py?
Bell, Kevin wrote: I've been looking around, but haven't found a place to download the md5.py module. I need it to run the dupinator.py Anyone know where to find it? Google knows... Stefan -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Attributes of builtin/extension objects
George Sakkis wrote: - Where do the attributes of a datetime.date instance live if it has neither a __dict__ nor __slots__ ? - How does dir() determine them ? py from datetime import date py d = date(2003,1,23) py dir(date) == dir(d) True py for attr_name in ['day', 'month', 'year']: ... attr_val = getattr(date, attr_name) ... print attr_name, type(attr_val) ... day type 'getset_descriptor' month type 'getset_descriptor' year type 'getset_descriptor' So all the instance attributes are actually handled by descriptors on the type. So datetime.date objects don't really have any instance attributes... - dir() returns the attributes of the instance itself, its class and its ancestor classes. Is there a way to determine the attributes of the instance alone ? I'm just guessing now, but perhaps if no __dict__ or __slots__ is available, all instance attributes are managed by descriptors on the type? STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: python CGI,sybase and environ variables
[EMAIL PROTECTED] wrote: hi i am writing a CGI to process some database transactions using the Sybase module. so in my CGI script, i have: ... import Sybase import cgitb; cgitb.enable(display=1 , logdir=/tmp/weblog.txt) ... ... the problem is , everytime i have ImportError: No module named Sybase flagged out. at first i think it's library path misconfiguration, so i put os.environ[SYBASE] = '/path/to/sybase' os.environ[LD_LIBRARY_PATH] = '/path/to/sybase/lib' before i import Sybase. but its still the same error Ok.so now, is it necesary to configure the web server's nobody user's profile to point to the Sybase libraries? or worse, configure root's profile to point to Sybase libraries? what's could be wrong? thanks for any help rendered. You should try adding /path/to/sybase to sys.path as well as/rather than putting it in an environment variable. sys.path is what the interpreter uses to find importable modules. 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