ANN: mountpy 0.5
mountpy is a python script for quick automatic mounting and umounting of external filesystems, especially suited for USB removable devices. mountpy is developed on linux, and is meant for modern linux systems. This is version 0.5, changes from previous version: - use setuid wrapper from python source distribution (suggested by Олег Бройтман/Oleg Broytmann) - do not try to umount directory which is not a mountpoint (caused some confusing, though harmless, messages) URL: http://kassiopeia.juls.savba.sk/~garabik/software/mountpy/ License: GPL -- --- | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__garabik @ kassiopeia.juls.savba.sk | --- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Release 0.54 of Task Coach
Hi all, I'm pleased to announce release 0.54 of Task Coach. New in this release: Bugs fixed: * The accelerators INSERT and Ctrl+INSERT were mapped to 'c' and 'Command-Copy' on the Mac, which caused Task Coach to create a new task whenever the user typed a 'c'. Fixed by changing the accelerators for new task and new subtask to Ctrl+N and Shift+Ctrl+N (on the Mac only). * It was possible to enter control characters -- by copy-and-pasting -- resulting in invalid XML in the Task Coach file. * One python file was missing in the source distribution of release 0.53. Added a test to check that all python files in the source are actually added to the source distributions, so hopefully this will never happen again. Feature added: * Effort can be exported as iCalendar (ICS) file and imported into e.g. Mozilla Sunbird. Each effort record is exported as a VEVENT. This is an experimental feature. Patch provided by Gissehel. What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://taskcoach.niessink.com https://sourceforge.net/projects/taskcoach/ A binary installer is available for Windows XP, in addition to the source distribution. Note that Task Coach is alpha software, meaning that it is wise to back up your task file regularly, and especially when upgrading to a new release. Cheers, Frank -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
BayPIGgies: January 12, 7:30pm (Google)
The next meeting of BayPIGgies will be Thurs, January 12 at 7:30pm at Google, room Tunis. Meet in the lobby of building 43. This will be a combo meeting: * First Marilyn Davis will practice her Why Python? talk -- she's looking for feedback and suggestions on improving it. * We'll fill the rest of the time with a Newbies Night; this is your opportunity to get realtime responses to questions about Python BayPIGgies meetings alternate between IronPort (San Bruno, California) and Google (Mountain View, California). For more information and directions, see http://baypiggies.net/ Before the meeting, we sometimes meet at 6pm for dinner. Discussion of dinner plans is handled on the BayPIGgies mailing list. Advance notice: We need speakers for February and later; the February meeting is currently reserved for PyCon speakers wanting practice, and the March meeting will probably be a PyCon wrap-up. Please e-mail [EMAIL PROTECTED] if you want to suggest an agenda (or volunteer to give a presentation). -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ 19. A language that doesn't affect the way you think about programming, is not worth knowing. --Alan Perlis -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Translate this to python?
Heiko Wundram [EMAIL PROTECTED] writes: I know this, and that's one of the reasons I'm a little at odds with Python 3000... some things are so basic (such as xrange) I wouldn't want to have to implement them every time I need such a beast. Itertools.count could be extended to replace xrange. Unless of course range() becomes more clever and returns an iterator in case the amount of memory to store the needed range is too large... That could break things. Range is supposed to return a list. -- http://mail.python.org/mailman/listinfo/python-list
Re: csv format to DBase III format
Peter Otten wrote: [EMAIL PROTECTED] wrote: I need to transfer csv format file to DBase III format file. How do i do it in Python language? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715 Peter Hi, I create a dbf file, it can be opened by Excel but it cannot be opened by Access. Where is the error in my script. My script is as follows, def dbfwriter(f, fieldnames, fieldspecs, records): Return a string suitable for writing directly to a binary dbf file. File f should be open for writing in a binary mode. Fieldnames should be no longer than ten characters and not include \x00. Fieldspecs are in the form (type, size, deci) where type is one of: C for ascii character data M for ascii character memo data (real memo fields not supported) D for datetime objects N for ints or decimal objects L for logical values 'T', 'F', or '?' size is the field width deci is the number of decimal places in the provided decimal object Records can be an iterable over the records (sequences of field values). # header info ver = 3 now = datetime.datetime.now() yr, mon, day = now.year-1900, now.month, now.day numrec = len(records) numfields = len(fieldspecs) lenheader = numfields * 32 + 33 # lenrecord = sum(field[1] for field in fieldspecs) + 1 num = 0 for field in fieldspecs : num = num + int(field[1]) lenrecord = num + 1 hdr = struct.pack('LHH20x', ver, yr, mon, day, numrec, lenheader, lenrecord) f.write(hdr) # field specs for name, (typ, size, deci) in itertools.izip(fieldnames, fieldspecs): # name = name.ljust(11, '\x00') name = name.ljust(11) fld = struct.pack('11sc4xBB14x', name, typ, size, deci) f.write(fld) # terminator f.write('\r') # records for record in records: f.write(' ')# deletion flag for (typ, size, deci), value in itertools.izip(fieldspecs, record): if typ == N: # value = str(value).rjust(size, ' ') value = str(value).rjust(size) elif typ == 'D': # value = value.strftime('%Y%m%d') value = value elif typ == 'L': value = str(value)[0].upper() else: # value = str(value)[:size].ljust(size, ' ') value = str(value)[:size].ljust(size) assert len(value) == size f.write(value) # End of file f.write('\x1A') f.close() # --- # Example calls if __name__ == '__main__': import sys, csv from cStringIO import StringIO # from operator import itemgetter # Create a new DBF # f = StringIO() f = open('test.dbf','w') fieldnames = ['CUSTOMER_ID','EMPLOY_ID','ORDER_DATE','ORDER_AMT'] fieldspecs = [('C',11,0),('C',11,0),('D',8,0),('N',12,2)] records = [['MORNS','555','19950626','17.40'],\ ['SAWYH','777','19950629','97.30'],\ ['WALNG','555','19950522','173.40']] dbfwriter(f, fieldnames, fieldspecs, records) William -- http://mail.python.org/mailman/listinfo/python-list
Re: How run web software *locally* easily?
For development I run my own modified version of CGIHTTPServer. It is called CGITHTTPServerWithSSI - http://www.voidspace.org.uk/python/recipebook.shtml#ssi It implements *some* SSI functions and allows you to maintain sites in *two* folders. A main folder and a second 'development' folder that just has stuff you're working on. It looks in the development folder first. The HTTPServer classes make great base classes for messing around with your own custom implementations for testing. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Working Firedrop2 anywhere?
Uhm... how about emailing the maintainer ? I use Firedrop2 every day... sometimes twice a day ;-) The only dependencies are Wax and wxPython. Installation instructions are on the homepage at : http://www.voidspace.org.uk/python/firedrop2/index.shtml#installing Download link is : http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=firedrop2.zip Let me know if this doesn't work for you. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32 Binary-only for 2.3.x?
Out of interest, doesn't the Python binary use the registry (and environment variables) for building sys.path ? Won't you still have conflicting path issues if you use an alternative binary with an existing 'normal' install ? All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft IronPython?
Max M wrote: First of they would need to make Python a strategic platform for corporations, so that it was used practically everywhere on Windows. Actually, if Python gets used everywhere on Windows, I'll be happy, pure Python or no pure Python :) Visual Python 2010 anyone? -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft IronPython?
Max M wrote: First of they would need to make Python a strategic platform for corporations, so that it was used practically everywhere on Windows. Then it would have the powerbase to change the lanuage and make an incompatible version that they could control. As far as I can see C## has that role for them. So I don't see how Python should be in any danger. If Python would create a Py3EE spec and make it an industry standard, provide a reference implementation and attract bluechips like Accenture, Bearing Point, Cap Gemini and IBM, Microsoft would be on the stage in order to improve it. Currently Python is still a cute little language, with plenty of bindings but few interesting products, that keeps attention among nerds and some consultants, but nothing more. Java, C++, C# and VB are playing in an own league. -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI question
An easier way is to use the cgi module. form = cgi.FieldStorage() form is a dictionary like object where each key is the parameter and each entry ahs a 'value' attribute that represents the value. You can use the ``getform`` function from cgiutils to turn it straight into a dictionary. See http://www.voidspace.org.uk/python/cgiutils.html The cgi module handles parsing hte query string for you. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Path and Unicode woes
Not full help - but still a pointer. E%3A/ isn't a unicode issue - but a value that is HTML escaped. MEaning (I presume without looking it up) 'E:/' - your file path. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Quickest way to make py script Web accessible
Turning a script into a CGI is a brain-dead easy way of web-enabling a script. You could even make the script dual purpose by checking for the existence of CGI environment variables. If they exist the script is running as a CGI. There are lots of resources on the internet on how to write CGIs. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Returning Values from Bash Scripts
HI all, How to execute bash scripts from python (other than using os.popen) and get the values that those bash scripts return. I would be happy if someone could help me out in this.. thanks in advance.. With Regards, Chakkaradeep -- http://mail.python.org/mailman/listinfo/python-list
os.environ['PATH'] missing
This is a hard question to ask because I can't reproduce the problem other than restarting several times over until it happens again. I'm using Zope and Plone for a website on this debian linux vserver and when I restart it it runs some /etc/init.d/zope restart scripts and things fail in zope because somewhere deep in there the following raises an AttributeError that 'PATH' doesn't exist: foo = os.environ['PATH'] How can it not be present? What might cause this seemingly random situation? Has anybody had similar experiences where 'PATH' is not present in os.environ? -- http://mail.python.org/mailman/listinfo/python-list
Re: config errors on Freebsd and python 2.3
David Bear wrote: I need python 2.3. I have freebsd 4.10-releng. when configuring python I received the following: ./configure --prefix=/home/webenv config-results ... I don't plan on using curses -- so I'd like to ignore this. But, I'm just wondering if there is an 'easy' fix... I've tried to fix it, still happens on Python 2.4.2 on FreeBSD6.0. Don't sweat it , Curtis -- http://mail.python.org/mailman/listinfo/python-list
Detecting Python Installs from the Windows Registry
Hello all, I'm creating a py2exe program (for Windows) that needs to detect all version of Python installed on the machine. Because it is running under py2exe it doesn't have access to the Python environment variables. Does anyone know how to use _winreg to get path information (location of install) for all versions of Python installed (and also which is the most recent) ? Googling the group didn't quickly turn up the answer, and I thought *someone* was likely to know easily... Thanks Fuzzyman http://www.voidspace.org.uk/python/idnex.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Display of JPEG images from Python
You can f.i. use wxPython (www.wxPython.org). Here is a compact and ugly, but (almost) minimal, example of a python script that shows an image file: import wx a = wx.PySimpleApp() wximg = wx.Image('img.jpg',wx.BITMAP_TYPE_JPEG) wxbmp=wximg.ConvertToBitmap() f = wx.Frame(None, -1, Show JPEG demo) f.SetSize( wxbmp.GetSize() ) wx.StaticBitmap(f,-1,wxbmp,(0,0)) f.Show(True) def callback(evt,a=a,f=f): # Closes the window upon any keypress f.Close() a.ExitMainLoop() wx.EVT_CHAR(f,callback) a.MainLoop() -svein -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple clients updating same file in ftp
Mike Meyer wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] writes: here's a simple-minded suggestion: have the first client create a text file on the remote server, and delete it when it is finished updating. The second client can check for existence of this file before trying to update. That's an old hack, dating back to at least Unix v6. The problem is the window between check for lock file and create lock file. The solution is to use an atomic create-or-fail action for the lock file. Exatly what that is will depend on your server, but things to check on are rename and mkdir. mkdir is good - if the directory already exists an error will be raised, this means you don't need to check for it's existence (meaning a race condition in between checking and attempting to create). If two mkdirs occur simultaneously then it is up to the OS to return an error to one of them. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml 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: Removing Duplicate entries in a file...
Hi there, I'm just curious to know as to how the changes you have suggested will solve the problem. Instead of appending (what I was doing), now we are opening and storing the files in 'binary' format. All the other entries in my file will be gone when I write into the file again. What I actuall need is this - I have some dictionary values stored in a file. I retrieve these entries based on the key value specified by the user. Now if I want to modify the values under a particular key, I first search if that key exists in the file and if yes retrieve the values associated with the key and modify them. Now when I re-insert this modified key-value pair back in the file. I have 2 entries now (one is the old wntry and the second is the new modified one). So if I search for that key the next time I'll have 2 entries for it. That's not what we want. So how do I remove the old entry without the other values getting deleted ? In other words, keeping the other entries as it is, I want to update a particular key-value pair. Let me know in case any bright idea strikes... -- http://mail.python.org/mailman/listinfo/python-list
Re: - Requesting Comments for Process Definition and Presentation
Xavier Morel wrote: Ilias Lazaridis wrote: b) to retrieve feedback subjecting the Process Definition itself (content of diagramms, clarity, terminology etc.) This is a lie, and you know it. I've said it before, i'll say it again; medical insurance premiums should be lower for people who know how to use killfiles. -- http://mail.python.org/mailman/listinfo/python-list
Viewing Binary Data
Hello, I would like to display a file in its binary form (1s and 0s), but I'm having no luck... Any thoughts would be most appreciated. Cheers! Cuyler -- http://mail.python.org/mailman/listinfo/python-list
Re: Translate this to python?
Xavier Morel wrote: While xrange does have it's place in Python, it has very few actual uses (yours being one of the few), and is usually more harmful than beneficial. While the deprecation of xrange is not that soon, it is part of the Python 3000 PEP (http://www.python.org/peps/pep-3000.html#id38) along with the deprecation of most FP-facilities of Python (filter, map, reduce). It should also be noted that reimplementing xrange when needed is trivial and can be done with a 5-lines generator for the minimal version (1 argument, 0-n range) and probably less than 10 lines for the full blown version equivalent to the current one (including start, end and step arguments) Seems that xrange() would be deprecated because range() will be the lazy version, so a name change or more like that the current range(), i.e. the one that returns a list will be deprecated, feature wise. -- http://mail.python.org/mailman/listinfo/python-list
Converting milliseconds to human amount of time
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. 4 days, 2 hours, 25 minutes, 10 seonds.? Is there a function from the time module that can do this? Thanks, Harlin Seritt -- http://mail.python.org/mailman/listinfo/python-list
Newbie Question: CSV to XML
Hi, Would anyone be willing to give me some feedback about this little script that I wrote to convert CSV to XML. I'll happily admit that I still have a lot to learn about Python so I'm always grateful for constructive feedback. Thanks, Greg ### #csv to XML conversion utility import os, re, csv root = raw_input(Enter the path where the program should run: ) fname = raw_input(Enter name of the uncoverted file: ) print given,ext = os.path.splitext(fname) root_name = os.path.join(root,fname) n = given + '.xml' outputName = os.path.join(root,n) reader = csv.reader(open(root_name, 'r'), delimiter=',') output = open(outputName, 'w') output.write('?xml version=1.0 encoding=utf-8?em:table\ncore:title/') output.write('\ncore:legend %s %s /core:legend\ntable frame=none colsep=0 rowsep=0\ntgroup cols=11 colsep=0 rowsep=0\ntbody valign=bottom' % ('TAS input file for ', given)) for row in reader: for i in range(0, len(row)): if i == 0: output.write('\nrow\nentry colname=col%s%s/entry' % (i, row[i])) if i 0 and i len(row) - 1: output.write('\nentry colname=col%s%s/entry' % (i, row[i])) if i == len(row) - 1: output.write('\nentry colname=col%s%s/entry\n/row' % (i, row[i])) output.write('\n/tbody\n/tgroup\n/table\n/em:table') output.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: error rising while connecting oracle 9i
python_eager wrote: Hi i am connecting my database oracle 9i. While connecting i am getting the following error connection = cx_Oracle.connect(myusername, mypassword, python) RuntimeError: Unable to acquire Oracle environment handle Do you have the Oracle client installed? Might be something wrong with your ORA_HOME. Robert -- http://mail.python.org/mailman/listinfo/python-list
Renaming files in ftplib
Let's say I have a file called 'test.c' on my local machine and I'm ftping a file with similar name from a remote computer. I want to prefix the file ftped over with a T_, how do I do that through ftplib in python? Thanks Thierry -- http://mail.python.org/mailman/listinfo/python-list
Re: C regex equiv to Python implementation?
Ganesan, I'm trying to stay portable between Windows and Linux. My app will run on Linux when deployed. But we do a lot of simulation on Windows because of better dev tools available on Windows. So I really want a regular expression implementation that'll compile under MS VS 2003 C++ and also under Gnu C++ for Linux on both x86 and ARM targets. -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft IronPython?
After downloading and trying out Ironpython, I have the following comments: 1) I like the idea of Python under .net 2) I like the support for both Microsoft math lib,and Python's math lib Will Microsoft maintain the compatability between standard python with the addition of their libs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Occasional OSError: [Errno 13] Permission denied on Windows
File attributes may be an issue to. Take look at the recipe at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303343 which ensures the file attributes are normal before you delete it. I don't think file attributes are an issue, because generally I can manually delete the file in question, and sometimes my app is eventually able to delete the file. You're not suggesting that some other process is temporarily changing the file attributes, are you? -- http://mail.python.org/mailman/listinfo/python-list
Double Click Mouse Event in Tkinter
Creating a Windows application: Double-Button-1 mouse event has a conflict when there is also a binding to the Button-1 event. It seems like a silly oversight that performing a double click will also initiate the single click action. Has anyone figured out a way to circumvent this problem? Right now I am making the Double click function undo the action my Single click function does, but this is very annoying, especially since the action that is bound to the Single click flashes for a second. -- http://mail.python.org/mailman/listinfo/python-list
Double Click mouse event problems
I tried to post this a few seconds ago and isn't showing. My apologies if it posts twice. I am creating a Windows application: The mouse event Double-Button-1 has a conflict when the Button-1 event also has a binding. Double clicks will first perform the single click action. This seems a little silly. Anyone know how to circumvent this? Right now I am having the function that is bound to the double click event undo the action the single click event performs. This is annoying and it flashes the single click event for a split second before the double click takes over. -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC programming with python (newbie) - please help
bwaha wrote: I'd appreciate some experience from the gurus out there to help me understand how to implement MVC design in python code. I'm neither a guru nor an expert, have never used wxpython, and am not qualified to advise on MVC!! But until someone more qualified arrives here's some code from a relative newbie. It's maybe not of any use in itself, but hopefully it won't lead you astray either. Hope it helps. Gerard Model class Study(object): def __init__(self, name, file): self.name = name self.file = file class Project(object): def __init__(self, name): self.name = name self.studies = [] End Model View class TreeViewNode(object): children = [] tag = NODE class StudyNode(TreeViewNode): def __init__(self, study): self.tag = study.name self.file = study.file self.children = None class ProjectNode(TreeViewNode): def __init__(self, project): self.tag = project.name for study in project.studies: self.children.append( StudyNode(study) ) class ProjectTreeView(TreeViewNode): def __init__(self): self.tag = All Projects def add_node(self, node): assert isinstance( node, ProjectNode ) self.children.append(node) End View data=''' BEGIN PROJECT mpi6_0 STUDY Cyc0302_0 cyc0302_beanoz_x1.sdy STUDY Cyc0305_0 cyc0305_beanoz_x1.sdy STUDY Cyc0308_0 cyc0308_beanoz_x1.sdy STUDY Cyc0311_0 cyc0311_beanoz_x1.sdy STUDY Cyc0314_0 cyc0314_beanoz_x1.sdy END PROJECT BEGIN PROJECT mpi6_1 STUDY Cyc0302_1 cyc0302_beanoz_x1.sdy STUDY Cyc0305_1 cyc0305_beanoz_x1.sdy STUDY Cyc0308_1 cyc0308_beanoz_x1.sdy STUDY Cyc0311_1 cyc0311_beanoz_x1.sdy STUDY Cyc0314_1 cyc0314_beanoz_x1.sdy END PROJECT ''' if __name__ == '__main__': import StringIO src = StringIO.StringIO(data) projects = [] for line in src: parts = line.split(' ') begin = parts[0] == 'BEGIN' studyline = parts[0] == 'STUDY' end = parts[0] == 'END' if begin == True: project = Project( parts[2][1:-1] ) elif studyline == True: project.studies.append( Study(parts[1][1:-1], parts[2]) ) elif end == True: projects.append( project ) for proj in projects: print 'PROJECT: ', proj.name for study in proj.studies: print ' ', study.name MyTreeView = ProjectTreeView() for proj in projects: MyTreeView.add_node( ProjectNode(proj) ) print MyTreeView -- http://mail.python.org/mailman/listinfo/python-list
Copying files between different linux machines
Let's say I have two linux machines with the following names: -linone -lintwo If I'm currently on linone and if I want to copy a bunch of files from lintwo into linone, how can that be done in a python script without using ftp? Thanks Thierry -- http://mail.python.org/mailman/listinfo/python-list
Re: Occasional OSError: [Errno 13] Permission denied on Windows
I tried something not exactly like this, but in the same spirit. I don't generally have a list of files I want to delete - just one. I try to delete it and if I get errno 13 I sleep for a little while (0.2) and then try again. If the same problem then I add 1 sec to the sleep time and try again. After sleeping about 10 sec total I give up. Unfortunately, one of my testers still experiences the problem even with this fix. I am surprised that a virus checker or file indexer would hold onto a file for so long. Ugh. Patrick Maupin wrote: Tim Peters wrote: In that case, anything that burns some time and tries again will work better. Replacing gc.collect() with time.sleep() is an easy way to test that hypothesis; because gc.collect() does an all-generations collection, it can consume measurable time. An slight enhancement to this hypothesis-tester (which might even approach being production-worthy) would be to maintain a list of items which were not deleted on a particular pass. Sleep after each pass, then try to kill all the items on the list again. Maintain a counter of the number of passes which have been made since the last time the undeleted item list shrank (via a completed deletion), and if the total time exceeds 'x' or the number of passes since a completed deletion exceeds 'y', then bail and ask the user to help you out. Regards, Pat -- http://mail.python.org/mailman/listinfo/python-list
Help wanted with md2 hash algorithm
hi all, below you find my simple python version of MD2 algorithm as described in RFC1319 (http://rfc1319.x42.com/MD2). It produces correct results for strings shorter than 16 Bytes and wrong results for longer strings. I can't find what's wrong. Can anybody help? Regards Wolfgang - #--- MD2 validation data md2_test = [ ('', '8350e5a3e24c153df2275c9f80692773'), (a, '32ec01ec4a6dac72c0ab96fb34c0b5d1'), (abc, 'da853b0d3f88d99b30283a69e6ded6bb'), (message digest, 'ab4f496bfb2a530b219ff33031fe06b0'), (abcdefghijklmnopqrstuvwxyz, '4e8ddff3650292ab5a4108c3aa47940b'), (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789, 'da33def2a42df13975352846c30338cd'), (12345678901234567890123456789012345678901234567890123456789012345678901234567890, 'd5976f79d83d3a0dc9806c3c66f3efd8' ) ] #--- 256-byte random permutation constructed from the digits of pi PI_SUBST = [41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63, 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50, 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165, 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210, 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157, 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27, 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233, 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20] PADDING = [.join(map(chr, [i]*i)) for i in range(17)] SIZE = 16 #-- def md2(m): ## (1) prepare message #--- append to m i byte with value i, len(m) % 16 == 0 padLen = SIZE - len(m) % SIZE m += PADDING[padLen] #--- compute checksum C of m and append it to m C = [0] * SIZE L = 0 for i in range(len(m) / SIZE): m16 = m[i*SIZE : (i+1)*SIZE] for j in range(SIZE): c = ord(m16[j]) C[j] = PI_SUBST[ c ^ L ] L = C[j] C = .join( map(chr, C) ) m += C ## (2) compress message X = [0] * 48 # 'compressor' for i in range(len(m) / SIZE): # fill X m16 = m[i*SIZE : (i+1)*SIZE] X[16:32] = map(ord, m16) X[32:48] = [ a^b for (a,b) in zip(X[16:48], X[:16]) ] # compress m t = 0 for j in range(18): for k in range(48): t = X[k] ^ PI_SUBST[t] X[k] = t t = (t+j) % 256 X = .join(map(lambda d: %02x % d, X[:SIZE])) return X def test(): for (i, j) in md2_test: md = md2(i) print Message: %s % i print My MD:%s % md print Test MD:%s % j print %s % (md== j) print if __name__ == __main__: test() -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC programming with python (newbie) - please help
Gerard Flanagan wrote: bwaha wrote: I'd appreciate some experience from the gurus out there to help me understand how to implement MVC design in python code. Badly snipped, not pretending to be a 'guru' Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting milliseconds to human time
Max Erickson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] the hard way(in that you have to do it yourself): def prntime(ms): s=ms/1000 m,s=divmod(s,60) h,m=divmod(m,60) d,h=divmod(h,24) return d,h,m,s Or abstracted... def decd (n, base): Decompose numeric value 'n' into components k[0:n] such that n = sum (k[N-i]*base[M-i]) for i=0...N where N is the length of k and M is the length of base. Examples: To convert 310255 seconds to [days, hours, minutes, seconds]: decd (310255, [3600*24, 3600, 60, 1]) [3, 14, 10, 55] To convert 86.182 hours to [days, hours, minutes, seconds]: decd (86.182, [24, 1, 1./60, 1./3600]) [3.0, 14.0, 10.0, 55.0] To convert 78 (decimal) to binary: decd (78, [128, 64, 32, 16, 8, 4, 2, 1]) [0, 1, 0, 0, 1, 1, 1, 0] To break a decimal number into digits: decd (463, [1000, 100, 10, 1]) [0, 4, 6, 3] r = [] for b in base: d, n = divmod (n, b) r.append (d) return r -- http://mail.python.org/mailman/listinfo/python-list
Double Click mouse event problems
I am creating a Windows application: The mouse event Double-Button-1 has a conflict when the Button-1 event also has a binding. Double clicks will first perform the single click action. This seems a little silly. Anyone know how to circumvent this? Right now I am having the function that is bound to the double click event undo the action the single click event performs. This is annoying and it flashes the single click event for a split second before the double click takes over. -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's Edu Corner: the bug-reporting attitude
Apoologies for the multiple posts -- please blame Google. -- http://mail.python.org/mailman/listinfo/python-list
Re: error rising while connecting oracle 9i
Check: 1. Whta is the Python version your running, with py import sys py print sys.version 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] 2. Download the correct version of cx_Oracle see http://www.cxtools.net/default.aspx?nav=cxorlb then execute the command again - supposed your user is myusername, your assword is mypassword, and your dsn is python. The dns should match an entry in the 'tnsnames.ora' - the location of this file depends on running Oracle on a Windows or Unix server. If you need more help please post more info like: * Oracle version (including subnumbers) * Python version * cx_Oracle version * OS version * DNS entry * exact traceback -- http://mail.python.org/mailman/listinfo/python-list
Re: Try Python update
Mike Meyer wrote: Xavier Morel [EMAIL PROTECTED] writes: [Old message and Xavier's question] [Mike's reply to Xavier] Since Python doesn't have any way to secure the interface built-in, i'd be interrested in that. Devan apparently doesn't have as cooperative an ISP, and is working on securing the interpreter. What he's done may be more interesting. It's not particularily interesting. The C code simply has more attributes restricted in restricted mode, disabling in particular __subclasses__. The rest is creating safe __builtins__ and only giving them some modules (but again, importing is still largely broken, although one liners are still possible). In any case, I don't know how secure it actually is, since nobody seems to go further than import os or import sys. So if you're bored, you can try to break into it. I haven't secured modjelly entirely, and it might be possible to trick modjelly into executing code by using descriptors when it tries to pull out all of the information. Then again, I haven't even added support for properties in it yet. Plus it has no support for if you delete critical attributes which are needed to recreate the object. Still, I think it's good enough to deter any random person from trying to wipe the server for now. -- http://mail.python.org/mailman/listinfo/python-list
Re: libpython2.4.so
ahh, it all makes sense now, thank you. -- http://mail.python.org/mailman/listinfo/python-list
wxPython installation woes on OpenSUSE
Hi all, I downloaded the wxpython2.6 tar ball and tried building an rpm from it in an opensuse 10 computer. The command i used was rpmbuild -tb wxpython tar file The build worked fine and i found an 3 rpms in /usr/src/packages/RPMS/i586 Then proceeded to install the which went without any hiccups... but when i import the wx package like so import wx i get the following error... Cant figure out whats happening... Any help would be appreciated Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/__init__.py, line 42, in ? from wx._core import * File /usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py, line 4, in ? import _core_ ImportError: /usr/lib/wxPython-2.6.1.0-gtk2-unicode/lib/libwx_gtk2ud-2.6.so.0: undefined symbol: pango_x_get_context -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting milliseconds to human time
Harlin Seritt [EMAIL PROTECTED] writes: I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds # To iterate is human; to recurse, divine. def dhms(m,t): if not t: return (m,) return rl(m//t[0], t[1:]) + (m % t[0],) human_readable = '%d days %d hours %d minutes %d seconds'% \ dhms(msec//1000, (60, 60, 24)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting milliseconds to human time
Paul Rubin http://[EMAIL PROTECTED] writes: def dhms(m,t): if not t: return (m,) return rl(m//t[0], t[1:]) + (m % t[0],) Editing error, sigh. Meant of course to say return dhms(m//t[0], t[1:]) + (m % t[0],) -- http://mail.python.org/mailman/listinfo/python-list
Re: download full sites?
Try curl...its pretty cool.. and also wget... -- http://mail.python.org/mailman/listinfo/python-list
Re: Copying files between different linux machines
I'll presume you have ssh, scp on both boxes $ man ssh $ man scp $scp mydata.dat [EMAIL PROTECTED]:mydata.dat -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple clients updating same file in ftp
Fuzzyman [EMAIL PROTECTED] writes: Mike Meyer wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] writes: here's a simple-minded suggestion: have the first client create a text file on the remote server, and delete it when it is finished updating. The second client can check for existence of this file before trying to update. That's an old hack, dating back to at least Unix v6. The problem is the window between check for lock file and create lock file. The solution is to use an atomic create-or-fail action for the lock file. Exactly what that is will depend on your server, but things to check on are rename and mkdir. mkdir is good - if the directory already exists an error will be raised, this means you don't need to check for it's existence (meaning a race condition in between checking and attempting to create). If two mkdirs occur simultaneously then it is up to the OS to return an error to one of them. Except that some os designer (or the ftp server - remember, the OP is talking to an FTP server to do this!) may decide that mkdir on an existing directory isn't an error, since the directory exists afterward. Rename can also work, but again depends on how the os and FTP server decide to treat the case of renaming to an existing file. There may be other alternatives as well. If the OP weren't working through the FTP server, os.open with os.O_CREAT|os.O_EXCL would do the trick. 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: Copying files between different linux machines
Thierry Lam [EMAIL PROTECTED] writes: Let's say I have two linux machines with the following names: -linone -lintwo If I'm currently on linone and if I want to copy a bunch of files from lintwo into linone, how can that be done in a python script without using ftp? Use scp. 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: csv format to DBase III format
William wrote: Peter Otten wrote: [EMAIL PROTECTED] wrote: I need to transfer csv format file to DBase III format file. How do i do it in Python language? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715 I create a dbf file, it can be opened by Excel but it cannot be opened by Access. Where is the error in my script. No idea, but here's some brainstorming. f = open('test.dbf','w') First make sure that you open the file in binary mode 'wb'. If you have an application around that can generate dbfs you could compare a manually created file with the python-generated one. Have you tried the dbf with no records? If that is opened without error, you could successively add records until you find the culprit. Finally, if Excel and Access disagree about the dbf's validity, the Access import filter could be broken. Are there other filters for the Dbase family (Foxpro, Clipper)? Try one of them. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
[EMAIL PROTECTED] wrote: In fact, googling for referer and referrer reports a similar number of hits, unlike most misspellings. Terry You know, I almost mentioned that myself. Drives me crazy. Me too. I'm one of those people who, for better or worse, is a good speller. Words just look right or wrong to me and it bothers me when they look wrong. What's worse is the closely related problem of British/American English, though you sort of get used to it after typing s/colour/color/g or s/serialise/serialize/g for the thousandth time. The words look wrong to me, but they're correct in the context. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
Steven D'Aprano wrote: On Thu, 05 Jan 2006 05:21:24 +, Bryan Olson wrote: Steven D'Aprano wrote: Mike Meyer wrote: [...] Correct. What's stored in a list is a reference. Nonsense. What is stored in the list is an object. According to the Python Language Reference: Some objects contain references to other objects; these are called containers. Examples of containers are tuples, lists and dictionaries. [http://docs.python.org/ref/objects.html] Is it so hard to understand that the word reference has a general, imprecise meaning in common English (which is clearly how the quote above is using the word) while still having in the context of assignment and argument passing a more precise meaning which is dangerously misleading? What's pretty easy to understand at this point, is that Mike was right and you were wrong. Reference has a precise meaning here, it's what the Python language uses, and contrary to your reporting, it's what the rest of the discipline uses. Words are important -- not only for what they mean, but for what the connotations they carry. For people who come to Python from C-like languages, the word reference means something that is just not true in the context of Python's behaviour. Wrong. C does not have references, and the Python use is consistent with the rest of computer science. You seem to have read in things that it does not mean. Fix *your* thinking. That's why people come to Python with a frame that tells that what call by reference implies (I can do this...) and then they discover that they often *can't* do that. I'm sorry if you got confused, but please don't project it on the rest of the discipline. C does not have even references. [...] Thinking about Python's behaviour (it always passes references to objects) Just fix your thinking and don't attribute these problems to others. [...] If we were writing academic papers, we could define call by reference and objects contain references any way we liked, That would be a terrible thing to do. Just learn to use the meaning accepted in the discipline, and used in the Python doc. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
On Sat, 07 Jan 2006 01:29:46 -0500, Mike Meyer wrote: Call by object is the worst choice among the three, because object has such a vague meaning, so you never know what implications someone will come away with. So very unlike call by reference, right? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Visualisation Engine for Python
Thanks for all the help everyone. rod -- http://mail.python.org/mailman/listinfo/python-list
Re: pdb.py - why is this debugger different from all other debuggers?
Mike Meyer [EMAIL PROTECTED] writes: But if I had to choose between being able to play with objects interactively or being able to step through code, I'll take the interactive interpreter every time. Why would you have to choose? You've created a straw-man argument. No one has previously suggested *removing* tools or forcing one to use one and not the other! The thrust that started this thread and the intent was thoughts on *improving* debugging. You say you are happy with what you have. Great! But then out of the blue offer your non-help. And although that too wasn't the thrust of the thread either (soliciting volunteers), it's not like you apparently *had* been working on this either. Weird. Well, the tools I'm talking about here are ones that Python comes with. It may be simple-minded to assert that everyone who writes Python code uses the tools that come with Python, but it's not very bright to not use the tools that come with the language. Not if one uses *better* tools. :-) Again in this very thread another interpreter was mentioned which, alas, doesn't come with Python. But on many systems it is installed rather easily. It addresses some things that again in this thread have been noted as perhaps lacking in the stock Python-supplied interpreter. I'm all to aware that not everyone writes code as easy to understand as what I do. (And it just may be that not everyone finds reading your code as easy to understand as you think it is.) The correct solution for bad code was elucidated by Kernighan and Plauger nearly 30 years ago: Don't fix bad code. Rewrite it. I don't do that nearly often enough. I heartily agree. (But I also can't help note that this may be a little bit of a self-serving statement.) A good debugger is a valuable thing, and I've used some incredible debuggers, including one that actually implemented DWIM. Stepping through the code is one of the least valuable thing a debugger does, but it's also the thing that makes it a debugger. Hmmm. If that's really your view of what makes a debugger, I can see why it's not all that important to you. But this could another one of your exaggerate-to-make-absurd arguments. Now that you mention it, stepping in pydb.py does have this little thing that seems just a little different from the norm. When one steps through a class or even a script with lots of methods/functions, the debugger seems to stop at every def, which isn't all that exciting. And say in contrast to gdb's step/next, you can't give a count. (Perl allows one to enter an arbitrary expression to step/next into). These do tend to make stepping less useful. But as with the restart command that was mentioned at the beginning of the thread, it wasn't all that hard to address in the current code base. Pretty much everything else that a debugger does can be done by other tools. So tell me what tools you have to set a breakpoint somewhere in a program possibly based on variable values, inspect arbitrary values as you see fit and perhaps change them, and then either continue or restart the program depending on how long it took to get to the point and how messed up things were when you got there? None of this involves stepping, so by your definition it's something that doesn't need a debugger. As those tools improve, the value of the debugger decreases. Python has very good other tools. The argument also goes the other way. If one has a debugger that's lacking -- and it looks to me that pdb.py is a little bit neglected (in some cases I would even say not pythonic)-- then, sure, people are going to try to find ways to avoid using it. This too was mentioned on this thread. Without a doubt Python has good tools. And no doubt they will continue to improve as perhaps they should. But I don't see this as an argument for not to improving debugging in Python as well. -- http://mail.python.org/mailman/listinfo/python-list
Optional typecheck
Hello all! Please enlighten me about optional typecheck: 1) Will it be available in Python 2.5? 2) Will it support things like def f(a: int | float) 3) Will it support interface checking like def g(a: BookInterface) or even mix like def k(a: file | BookInterface) 4) Will it support things like def t(*args: T1 | T2, **kwds: T1 | T3) -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python allow access to some of the implementation details?
[EMAIL PROTECTED] wrote: Claudio Grondi wrote: Martin v. Löwis wrote: You can get somewhat faster in Python than your code if you avoid producing new long objects all the time, and do the task in chunks of 30 bits. It would be nice if you could explain why you consider chunks of 30 bits to be superior e.g. to chunks of 32 bits? write a C file that is a Python module If I understand you right, there is no way to get direct access to internal representation of Python objects by Python script language means provided in the standard Python 2.4.2 distribution. So the answer to the question in the subject is : NO (valid for what is provided in the standard Python distribution, but not valid when considering to write an own extension module in C) No need to re-invent the wheel. That extension has already been written. The GMPY module has a full suite of bit-functions: digits(...) digits(x[,base]): returns Python string representing x in the given base (2 to 36, default 10 if omitted or 0); leading '-' present if x0, but no leading '+' if x=0. x must be an mpz, or else gets coerced into one. That's nice function. A pity it's not in the standard Python distro as the inversion of the int() operation. What I am also looking for is a conversion to base 256 (i.e where the full byte is used and the string and the integer have the same actual content if on appropriate endian machine), which would make the bit extraction comparable easy and effective as the i.__hex__() based method. Using digits() instead of the code you have provided speeds the whole thing up two times (see attached code for details), but still is i.__hex__() the best way to go and could be improved probably only by direct conversion to base 256 or even higher base as e.g. 2**16 or 2**32. Claudio import time # dctLstOfBitsVsCharOfNibble is a dictionary with a key beeing one character # string representing hexadecimal value of a nibble and a value beeing a list # of bits of the nibble where the lowest bit is stored at index 0 of the list. # i.e. dctLstOfBitsVsCharOfNibble = { '0':[0, 0, 0, 0], '1':[0, 0, 0, 1], '2':[0, 0, 1, 0], '3':[0, 0, 1, 1], '4':[0, 1, 0, 0], '5':[0, 1, 0, 1], '6':[0, 1, 1, 0], '7':[0, 1, 1, 1], '8':[1, 0, 0, 0], '9':[1, 0, 0, 1], 'A':[1, 0, 1, 0], 'B':[1, 0, 1, 1], 'C':[1, 1, 0, 0], 'D':[1, 1, 0, 1], 'E':[1, 1, 1, 0], 'F':[1, 1, 1, 1] } # The dctLstOfBitsVsCharOfNibble dictionary can be generated by following code: # dctLstOfBitsVsCharOfNibble = {} # for intNibbleValue in range(0, 16): # lstBitReprOfCurrNibble=[] # for indxOfBit in range(0,4): # lstBitReprOfCurrNibble.append(intNibbleValueindxOfBit0x01) # #:for # lstBitReprOfCurrNibble.reverse() # dctLstOfBitsVsCharOfNibble['%X'%(intNibbleValue,)]=lstBitReprOfCurrNibble # #:for n = 0 NoOf32bitChunks = 0 lstBitsBitwiseAnd = [] lstBitsModulo = [] lstViaBitChunks = [] lstBitsViaHex = [] lstBitsGMPY = [] timeBitwiseAnd= -1 timeModulo= -1 timeBitsViaHex= -1 timeViaBitChunks = -1 timeGMPY = -1 bitChunkSize = 32 # must be = 32 while timeBitwiseAnd = timeBitsViaHex + 0.001: n = (n32) + 0x12345678 NoOf32bitChunks += 1 i = n lstBitsModulo = [] start = time.clock() while i: lstBitsModulo.append(i%2) i=i1 timeModulo = time.clock()-start i = n lstBitsBitwiseAnd = [] start = time.clock() while i: lstBitsBitwiseAnd.append(i0x01) i=i1 timeBitwiseAnd = time.clock()-start i = n lstViaBitChunks = [] bitFilter= 0 for dummy in range(bitChunkSize): bitFilter = (bitFilter1)+1 #:for start = time.clock() done = False while i: i1 = int(i bitFilter) # int() converts here a long-integer to integer i = bitChunkSize if i == 0: done = True for k in xrange(bitChunkSize): lstViaBitChunks.append(i1 1) i1 = 1 if done and i1==0: # if this is the top word, and no bits are left, we are done break #:if #:for #:while timeViaBitChunks = time.clock()-start i = n # lstBitsViaHex = [] start = time.clock() strHexOf_i = i.__hex__()[2:] if strHexOf_i[-1]=='L': strHexOf_i=strHexOf_i[0:-1] #:if intNoOfLeadingZeroBits = 0 lstBitsOfFirstNibble = dctLstOfBitsVsCharOfNibble[strHexOf_i[0]] while not lstBitsOfFirstNibble[intNoOfLeadingZeroBits] and intNoOfLeadingZeroBits 4: intNoOfLeadingZeroBits += 1 #:while if intNoOfLeadingZeroBits == 4: lstBitsViaHex = [] else: lstBitsViaHex = lstBitsOfFirstNibble[intNoOfLeadingZeroBits:] #:if for indxToStrHexOf_i in range(1,len(strHexOf_i)): lstBitsViaHex += dctLstOfBitsVsCharOfNibble[strHexOf_i[indxToStrHexOf_i]] #:for lstBitsViaHex.reverse() timeBitsViaHex = time.clock()-start import gmpy lstBitsGMPY = [] # start = time.clock() # i = gmpy.mpz(n) # f = gmpy.scan1(i,0)
PyQt Access Violations
I noticed that when I invoked the setCentralWidget() method using PyQt 3.13 on Python 2.3.5 opening and closing a widget associated with a main window would result in a Win32 access violation crash after a couple of times. Here's a generic snippet: class Application_Window(QMainWindow): def __init__(self): QMainWindow.__init__(self,None,'application main window',Qt.WDestructiveClose) def other_widget(self): self.this_widget=QWidget() self.setCentralWidget(self.this_widget) The only way I could avoid the crashes was to replace the setCentralWidget() method with: self.this_widget.show() Is there some fundamental error I was making in this, or is this a known bug? -- http://mail.python.org/mailman/listinfo/python-list
Re: download full sites?
[EMAIL PROTECTED] wrote: hi, does anyone know of any package that will download a full site for offline viewing? It will change all url to match local urls and follow a logical structure (the site's structure would be suffice).. Please tell me if you have heard of such a package.. thanks alot :D I thougt, that HarvestMan http://cheeseshop.python.org/pypi/HarvestMan/1.4.5%20final is THE tool to do that. Because haven't used it yet, still dowloading with a commercial OfflineExplorer program I have a license for, I would be glad to hear how it compares to the other in this thread mentioned tools. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting milliseconds to human amount of time
Harlin Seritt wrote: How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. 4 days, 2 hours, 25 minutes, 10 seonds.? Is there a function from the time module that can do this? Thanks, Harlin Seritt seconds = millis / 1000 # obviously minutes = seconds / 60 seconds %= 60 hours = minutes / 60 minutes %= 60 days = hours / 24 hours %= 24 All this using integer division, of course. This is probably much more verbose than the tersest soln, but it works (or should do - I haven't tested it). It's not strictly accurate (from a scientific/UTC perspective, as some minutes have 59 or 61 seconds rather than 60, but it's probably the best you need. --Max -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
James Tanis wrote: Quite honestly I've never heard of java being faster than.. well.. anything. Faster than Python? I really doubt it. Their are several libraries for game programming specifically as well as opengl, sdl, as well as several different audio systems/daemons.. I'd suggest browsing through the categories in python.org's module search engine. Disclaimer (:P): The majority of generalizations have some amount of exceptions, the java crack above was just my opinion - it was not really intended to offend any java addicts out there (the poor, miss-guided souls). While java is much slower than Python in developer-time (e.g. the time it takes to generate a working app, and the number of lines involved), (good) Java code running on the hotspot (JIT) VM is usually at least an order of magnitude faster than the equivalent Python code, if not faster. What's dog slow in Java is primarily the VM startup, and then the memory bloating, but as far as execution speed goes, pure Java code is much faster than pure Python much more often than the opposite (now that may change with Pypy, but Pypy is not done yet) Xavier -- http://mail.python.org/mailman/listinfo/python-list
Re: - E04 - Leadership! Google, Guido van Rossum, PSF
Ilias Lazaridis wrote: [...] For Software Engineer: Requirements: * BS or MS in Computer Science or equivalent (PhD a plus). Right here. This requirement is really funny. I thought google is somehow different. [...] from within this thread: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ee84d45c6857843a/295b4b21eb503bde I understand. Ok, thus Google is flexible in this. [sidenote: some jobs _require_ a degree by law] So, I like Google again (in this context). . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL implementation
circusdei wrote: I wrote this snippet with the intention of -- capturing a section of the screen whenever it changes. It could be implemented to log any sort of messaging system ( by saving consecutive images eg. 1.png...etc). #code import Image import ImageGrab lastchatbound = (21, 504) + (189, 516) img1 = ImageGrab.grab(lastchatbound) data1 = list(img1.getdata()) img2 = ImageGrab.grab(lastchatbound) data2 = list(img2.getdata()) # print `data1` pictnumber = 0 if data1 != data2: img1.save(`picnumber` + '.png') picnumber = picnumber + 1 else: print same #code -- it doesn't work yet and i'm not quite sure how the loops work yet ( i just sarted python last week). any help anyone could give me would be appreciated. if someone could rewrite it so it works, i could use that as an example for the future, thanks. - mb At the first glance the code looks almost ok. It is a good habit always to attach documentation of the error messages if any. What I can directly see is, that you need at least to initialize the picnumber (see above). Look in the Python documentation for the chapter with loops, read about the time module you will need to let the loop pause before taking the next screenshot and consider also, that maybe later it would be a good idea to have a way to stop the loop executing. Come back with the next revision of your code for further help if you get into trouble or wait until someone else provides you with appropriate working code. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
Sam Pointon wrote: What's worse is the closely related problem of British/American English, though you sort of get used to it after typing s/colour/color/g or s/serialise/serialize/g for the thousandth time. The words look wrong to me, but they're correct in the context. Hah! Canucks r00l! Most of those words look about equally good to us most of the time. (And it's not because of the beer!) (But our beer r00lz too.) -Peter Freezing-my-ass-off-in-Uxbridge Hansen -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] - Requesting Comments for Process Definition and Presentation
Xavier Morel wrote: Ilias Lazaridis wrote: b) to retrieve feedback subjecting the Process Definition itself (content of diagramms, clarity, terminology etc.) You are merely some kind of strange troll. You've built something that [...] - (off topic comments) note to readers: most of the comments are answered within those sections: http://lazaridis.com/core/index.html http://lazaridis.com/core/eval/index.html I can't see anything at this site what would make sense to me. you mean, you don't understand _anything_? No, he means that your website just doesn't make sense. I have understood this. that's why I wrote: And it seems I've many work to do. There is no purpose, no consistency, no way to understand what the website is supposed to hold, no way to find *informations* (and your colorful graphs with an informative level of somewhere below 0 do not count as information BTW). = missing purpose and consistency = missing way to understand main scope of website. = missing way to find informations = graphs have no information value I'll add that the color/style schemes are awfully misleading (why the hell are random words in bold-ocre, please go read a few books on = avoid bold-ocre interfaces and websites creation because you obviously don't have a clue there, Steve Krug's Don't Make Me Think would be a much required = Book suggestion Steve Krug's - Don't Make Me Think I operate based on public available resources. start), that the various categories are unclear, fuzzy and *never explained anywhere* = categories are unclear fuzzy = missing explanations for categories and that you claiming that you can *review websites* (for a fee on top of that) is insulting to people with actual skills in the field. from the inital message: I would like to ask for feedback on the Process Definition and Presentation. Essentially this is exactly what I've myself specialized to do. But I cannot apply the process to my own system. - Thank you for your feedback. - TAG.evolution.criticism.harsh . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt Access Violations
On Saturday 07 January 2006 1:06 pm, gregarican wrote: I noticed that when I invoked the setCentralWidget() method using PyQt 3.13 on Python 2.3.5 opening and closing a widget associated with a main window would result in a Win32 access violation crash after a couple of times. Here's a generic snippet: class Application_Window(QMainWindow): def __init__(self): QMainWindow.__init__(self,None,'application main window',Qt.WDestructiveClose) def other_widget(self): self.this_widget=QWidget() self.setCentralWidget(self.this_widget) The only way I could avoid the crashes was to replace the setCentralWidget() method with: self.this_widget.show() Is there some fundamental error I was making in this, or is this a known bug? What version of Qt? Phil -- http://mail.python.org/mailman/listinfo/python-list
How to format and print text.
Have been messing with python, but could´nt find out how to do printing with different Fonts. Any suggestions? Herdsman -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
On Sat, 07 Jan 2006 11:20:25 +, Bryan Olson wrote: Wrong. C does not have references, and the Python use is consistent with the rest of computer science. You seem to have read in things that it does not mean. Fix *your* thinking. Bryan, I'll admit that I'm no C/C++ programmer, and I frequently assume that if X is true for C++ it is also true for C, and vice versa. I appreciate being corrected when I make a mistake. However, in this case, I think you are confused by the term references. Of course pure C does not have the C++ data structure known as references, but that is hardly the only meaning of the word. Reference is a generic term for something which refers to something else, not just in plain English but also in computer science. Pointers are references. Indexes into a table are references. URLs are references. File names and file handles are references, as are keys from databases, and even raw memory addresses. http://en.wikipedia.org/wiki/Reference_(computer_science) I'll admit that my position on this question has changed. I no longer say that everything in Python is a reference is *false*, not in the weak, generic sense. How can it be? In the generic sense, Python names are references. (Under the hood, names may even be implemented as C++ references for all I know.) I will still argue that the term reference is harmful, not because it is technically incorrect, but because it activates incorrect mental models of Python's high-level behaviour in too many people. That's why people come to Python with a frame that tells that what call by reference implies (I can do this...) and then they discover that they often *can't* do that. I'm sorry if you got confused, but please don't project it on the rest of the discipline. Perhaps you should check out the beginning of the thread before making any additional comments. It wasn't me who was confused and asked Hey what's going on? I was told everything in Python is a reference, but when I do this it doesn't work. I'm not projecting anything on anyone. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
[EMAIL PROTECTED] Aside from the other responses (unittests, pychecker/pylint), you might also consider using __slots__ for new-style classes: I've been shouted at for suggesting exactly that! :-) http://groups.google.com/group/comp.lang.python/msg/fa453d925b912917 how-come-aahz-didn't-shout-at-you-ly'yrs, -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: config errors on Freebsd and python 2.3
why you are not installing it from ports? Martin v. Löwis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] David Bear wrote: I don't plan on using curses -- so I'd like to ignore this. But, I'm just wondering if there is an 'easy' fix... Not really, no. It's safe to ignore. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python allow access to some of the implementation details?
Claudio Grondi wrote: You can get somewhat faster in Python than your code if you avoid producing new long objects all the time, and do the task in chunks of 30 bits. It would be nice if you could explain why you consider chunks of 30 bits to be superior e.g. to chunks of 32 bits? With chunks of 32 bits, you might get negative numbers. Then, right-shifting bit-by-bit will never get you to zero. It also happens that the long ints are represented as arrays of 15-bit values, so that the shift by 30 *could* be implemented without shifts in the individual words; however, this optimization is not done. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling foreign functions from Python? ctypes?
Jean-Paul Calderone wrote: I could probably dig up a few more, if you want. So what's ctypes on top of this? another one: [EMAIL PROTECTED]:~$ python Python 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 Type help, copyright, credits or license for more information. import weakref ref = None class Target: ... def __del__(self): ... global ref ... ref = weakref.ref(self) ... def g(): ... w = Target() ... w = None ... print ref() ... g() Segmentation fault There are dozends of segfaults in Python indeed. Cheers, Carl Friedrich Bolz -- http://mail.python.org/mailman/listinfo/python-list
Stackless Python
Some time ago, I finally decided to check what Stackless was (exactly) and which were the theorical concepts behind it (continuations and all). I managed to find some documentations and papers, but most if not all of them are related to pre-2.0 Stackless. The issue is, I just can't seem to reach the Stackless website (http://stackless.com). Some specific pages of the site do work (http://stackless.com/spcpaper.htm), but the index itself always yields a 502 gateway error. Would anyone have more informations about that? It doesn't seem to be an issue on my side (since I tried to access the Stackless site from two different connections and 3 computers) but I can't rule it out. I should also note that Google is no good in this case as mostly yields fairly old results... -- http://mail.python.org/mailman/listinfo/python-list
Re: How to format and print text.
On 2006-01-07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Have been messing with python, but could´nt find out how to do printing with different Fonts. Any suggestions? Output postscript. -- Grant Edwards grante Yow! Did we bring enough at BEEF JERKY? visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Stackless Python
Xavier Morel wrote: I managed to find some documentations and papers, but most if not all of them are related to pre-2.0 Stackless. The issue is, I just can't seem to reach the Stackless website (http://stackless.com). Some specific pages of the site do work (http://stackless.com/spcpaper.htm), but the index itself always yields a 502 gateway error. I see the same problem. I asked Christian Tismer (author of stackless) to check whether the server has a problem. Cheers, Carl Friedrich Bolz -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
Aside from the other responses (unittests, pychecker/pylint), you might also consider using __slots__ for new-style classes: Alan I've been shouted at for suggesting exactly that! :-) Maybe Aahz didn't notice my post. The OP sort of seemed like he was pining for attribute declarations. __slots__ is the closest thing Python has to them. I don't use them myself (since I've basically avoided new-style classes so far). Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: question about mutex.py
Jean-Paul Calderone wrote: Did you read the module docstring? Of course, no multi-threading is implied -- hence the funny interface for lock, where a function is called once the lock is aquired. If you are looking for a mutex suitable for multithreaded use, see the threading module. I have always seen mutexes used in multi-threaded programs. I'm curious, what is the usefulness of a non-thread-safe mutex? I'm sure it must be good for something, I just can't figure it out. Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Translate this to python?
Paul Rubin wrote: Heiko Wundram [EMAIL PROTECTED] writes: Unless of course range() becomes more clever and returns an iterator in case the amount of memory to store the needed range is too large... That could break things. Range is supposed to return a list. Except that we're talking about Python 3.0, which will break things anyways. -- 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 to format and print text.
On 2006-01-07, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-01-07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Have been messing with python, but could´nt find out how to do printing with different Fonts. Any suggestions? Output postscript. Reportlab seems to be a popular way to do that... http://www.reportlab.org/rl_toolkit.html -- Grant Edwards grante Yow! I've read SEVEN at MILLION books!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Optional typecheck
Gregory Petrosyan wrote: Hello all! Please enlighten me about optional typecheck: 1) Will it be available in Python 2.5? 2) Will it support things like def f(a: int | float) 3) Will it support interface checking like def g(a: BookInterface) or even mix like def k(a: file | BookInterface) 4) Will it support things like def t(*args: T1 | T2, **kwds: T1 | T3) No, not til python 3.0, which is years off. For now you can use: http://www.ilowe.net/software/typecheck/ Or if you want static type checking with it speed boost instead of typechecking at runtime, there are lots of other options too. shedskin, pyrex, scipy.weave, boo -- http://mail.python.org/mailman/listinfo/python-list
BayPIGgies: January 12, 7:30pm (Google)
The next meeting of BayPIGgies will be Thurs, January 12 at 7:30pm at Google, room Tunis. Meet in the lobby of building 43. This will be a combo meeting: * First Marilyn Davis will practice her Why Python? talk -- she's looking for feedback and suggestions on improving it. * We'll fill the rest of the time with a Newbies Night; this is your opportunity to get realtime responses to questions about Python BayPIGgies meetings alternate between IronPort (San Bruno, California) and Google (Mountain View, California). For more information and directions, see http://baypiggies.net/ Before the meeting, we sometimes meet at 6pm for dinner. Discussion of dinner plans is handled on the BayPIGgies mailing list. Advance notice: We need speakers for February and later; the February meeting is currently reserved for PyCon speakers wanting practice, and the March meeting will probably be a PyCon wrap-up. Please e-mail [EMAIL PROTECTED] if you want to suggest an agenda (or volunteer to give a presentation). -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ 19. A language that doesn't affect the way you think about programming, is not worth knowing. --Alan Perlis -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 and proxies support ?
tomazi75-nospam(at)gmail.com wrote: Hello all, I've a problem using urllib2 with a proxy which need authentication. I don't have a way to test this myself but you can try the suggestion at the bottom of this page: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52199 Move your name/password to an HTTPBasicAuthHandler. -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
In article [EMAIL PROTECTED], Alan Kennedy [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] Aside from the other responses (unittests, pychecker/pylint), you might also consider using __slots__ for new-style classes: I've been shouted at for suggesting exactly that! :-) http://groups.google.com/group/comp.lang.python/msg/fa453d925b912917 how-come-aahz-didn't-shout-at-you-ly'yrs, Because I've been busy. I'd been saving Skip's post for when I had enough time to do it justice, but your URL saves me the trouble. ;-) -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ 19. A language that doesn't affect the way you think about programming, is not worth knowing. --Alan Perlis -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
Steven D'Aprano wrote: Bryan Olson wrote: Wrong. C does not have references, and the Python use is consistent with the rest of computer science. You seem to have read in things that it does not mean. Fix *your* thinking. Bryan, I'll admit that I'm no C/C++ programmer, and I frequently assume that if X is true for C++ it is also true for C, and vice versa. I appreciate being corrected when I make a mistake. However, in this case, I think you are confused by the term references. No, though I should have had references in quotes; C doesn't call anything a reference, so saying it confuses people about what references are doesn't make sense. [...] I'll admit that my position on this question has changed. I no longer say that everything in Python is a reference is *false*, not in the weak, generic sense. Of course it's false. Is indentation a reference? Is a comment a reference? The bad term there is everything, not reference. How can it be? In the generic sense, Python names are references. (Under the hood, names may even be implemented as C++ references for all I know.) I will still argue that the term reference is harmful, not because it is technically incorrect, but because it activates incorrect mental models of Python's high-level behaviour in too many people. Mike wrote that lists contain references. You said that was nonsense as they contain objects. His description was right and consistent with Python behavior. Yours was wrong and inconsistent with Python behavior. List storing references is the *right* mental model. That's why people come to Python with a frame that tells that what call by reference implies (I can do this...) and then they discover that they often *can't* do that. I'm sorry if you got confused, but please don't project it on the rest of the discipline. Perhaps you should check out the beginning of the thread before making any additional comments. It wasn't me who was confused and asked Hey what's going on? I was told everything in Python is a reference, but when I do this it doesn't work. I'm not projecting anything on anyone. Read more carefully. His problem was in understanding variable assignment in C versus Python: storage in a location versus name binding. He got some good explanations. Unfortunately there was also quite a bit of wrong reporting, which some of us are trying to correct. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Spelling mistakes!
Terry Hancock wrote: One thing I've figured out is that using the full spelling of a word instead of groovy programmer abbreviations makes it a lot easier to remember the names of things. Of course, like everything, that can be taken too far, so I still use things like bkg_clr too. Yeah, it's a real pain to constantly type breakage_clear every time. :-) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Please: 'module' object has no attribute 'compile'
I beleive so... I cannot know for sure becasue the models are not separate... they are in the python23.zlib file... I'm no sure how to check the file, it looks as if it is compiled (I'm new to python so forgive my ignorance) Kent Johnson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] livin wrote: my log... INFO urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', urllib.urlencode({'Action': 'hs.ExecX10ByName+Kitchen+Lights%2C+On %2C+100x=4y=6'})) INFO INFO File Q:\python\python23.zlib\urllib.py, line 78, in urlopen INFO File Q:\python\python23.zlib\urllib.py, line 159, in open INFO File Q:\python\python23.zlib\urllib.py, line 957, in splittype INFO AttributeError INFO : INFO 'module' object has no attribute 'compile' That line reads _typeprog = re.compile('^([^/:]+):') Do you have a module named 're' that is shadowing the library module of the same name? Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Double Click mouse event problems
scott_gui wrote: I am creating a Windows application: The mouse event Double-Button-1 has a conflict when the Button-1 event also has a binding. Double clicks will first perform the single click action. This seems a little silly. Anyone know how to circumvent this? Right now I am having the function that is bound to the double click event undo the action the single click event performs. This is annoying and it flashes the single click event for a split second before the double click takes over. This behavior is a feature of the double-click interface. Normal GUI design techniques provide double-click behavior that is not interfered with by the corresponding single-click behaviors. Step back and think about what is happening instead of focusing in tightly on mouse commands as being completely distinct operations. You wouldn't expect three distinct (and non-overlapping) behaviors from Button-1-Down, Button-1-Up and Button-1-Click, would you? If you must, provide a single-click that initiates a timer event, where the corresponding double-click turns off (or disables) the timer, and cause the single-click behavior when the timer triggers. On the original mouse, the buttons were ored together from the first down to all buttons-up. If the result was neither none-seen or all- seen, the operation happened at the release. Since that mouse had a 5-key paddle board (where paddle keys were included with the three mouse buttons in the above algorithm), you could specify 254 different values with a mouse and paddle-board. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Apology Re: Is 'everything' a refrence or isn't it?
Ben Sizer [EMAIL PROTECTED] wrote: ... assignment semantics that differ from languages such as C++ and Java, not the calling mechanism. In C++, assignment means copying a value. In Python, assignment means reassigning a reference. And in Java, it means just the same as in Python (with some unfortunate exceptions, in Java, for elementary types such as int -- but for all normal types, the meaning of assignment and parameter passing is just the same in Java as in Python). Considering that Java may have become the language most used for first courses in programming, it's unfortunate to propagate disinformation about its assignment semantics differing from Python's -- it will confuse people who know Java, and there are many of those. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python allow access to some of the implementation details?
Claudio Grondi [EMAIL PROTECTED] wrote: ... What I am also looking for is a conversion to base 256 (i.e where the full byte is used and the string and the integer have the same actual content if on appropriate endian machine), which would make the bit gmpy supplies that, too: gmpy.binary(x) or x.binary(): returns a portable binary representation (base-256 little endian) of an mpz object, suitable for saving into a file (or db, whatever) -- this string can later be passed as the first argument to function gmpy.mpz (with a second argument with value 256) to reconstruct a copy of the original mpz object. extraction comparable easy and effective as the i.__hex__() based method. I suspect bit-extraction is still going to be faster with getbit and friends, but I'm sure you can measure that for yourself (I'm stuck with a loaner machine these days, and don't currently have gmpy at hand). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: - E04 - Leadership! Google, Guido van Rossum, PSF
Anton Vredegoor [EMAIL PROTECTED] wrote: However I still maintain that I was never able to meet these fine people you speak about and which you seem to know because the cost involved (a few hundred euro to visit pycon for example) was too high compared to my food budget. Europython is cheap to attend, and has been held twice in Charleroi, Belgium, for example -- if you're in the Netherlands, you could have bycicled there, crashed with somebody (I've seen lots of impecunious people offered hospitality that way), and not spent more on food than you would by staying in the Netherlands. You'll have to invent some better excuse, to explain why you chose not to attend it. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python allow access to some of the implementation details?
Paul Rubin wrote: Claudio Grondi [EMAIL PROTECTED] writes: The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in computers memory? No it doesn't, and that's a good thing, since the internal representation is a little bit surprising (it stores 15 bits of the long int in each 16-bit word of the representation, to make the arithmetic routines a little simpler). If it were possible to 'tell' the %2 operation to operate only on one short of the integer number representation there will be probably no difference in speed. Is there a way to do this efficiently in Python like it is possible in C when using pointers and recasting? The usual trick to get at the contents of a long is to use hex conversion and maybe the array module (untested): a = '%x' % n if len(a) % 2 == 1: a = '0' + a s = array.array('B', binascii.unhexlify(a)) s now gives you the individual bytes of n. This is the _fastest_ approach I have seen so far (updated code attached). Thank you! Claudio import time # dctLstOfBitsVsCharOfNibble is a dictionary with a key beeing one character # string representing hexadecimal value of a nibble and a value beeing a list # of bits of the nibble where the lowest bit is stored at index 0 of the list. # i.e. dctLstOfBitsVsCharOfNibble = { '0':[0, 0, 0, 0], '1':[0, 0, 0, 1], '2':[0, 0, 1, 0], '3':[0, 0, 1, 1], '4':[0, 1, 0, 0], '5':[0, 1, 0, 1], '6':[0, 1, 1, 0], '7':[0, 1, 1, 1], '8':[1, 0, 0, 0], '9':[1, 0, 0, 1], 'A':[1, 0, 1, 0], 'B':[1, 0, 1, 1], 'C':[1, 1, 0, 0], 'D':[1, 1, 0, 1], 'E':[1, 1, 1, 0], 'F':[1, 1, 1, 1] } # The dctLstOfBitsVsCharOfNibble dictionary can be also generated by following code: # dctLstOfBitsVsCharOfNibble = {} # for intNibbleValue in range(0, 16): # lstBitReprOfCurrNibble=[] # for indxOfBit in range(0,4): # lstBitReprOfCurrNibble.append(intNibbleValueindxOfBit0x01) # #:for # lstBitReprOfCurrNibble.reverse() # dctLstOfBitsVsCharOfNibble['%X'%(intNibbleValue,)]=lstBitReprOfCurrNibble # #:for dctLstOfBitsVsOrdOfChar = {} for ordOfChar in range(256): dctLstOfBitsVsOrdOfChar[ordOfChar] = dctLstOfBitsVsCharOfNibble['%X'%(ordOfChar4,)] + dctLstOfBitsVsCharOfNibble['%X'%(ordOfChar0x0F,)] #:for # what gives: { # 0x00:[0, 0, 0, 0, 0, 0, 0, 0], # 0x01:[0, 0, 0, 0, 0, 0, 0, 1], # 0x02:[0, 0, 0, 0, 0, 0, 1, 0], # ... # 0xFD:[1, 1, 1, 1, 1, 1, 0, 1], # 0xFE:[1, 1, 1, 1, 1, 1, 1, 0], # 0xFF:[1, 1, 1, 1, 1, 1, 1, 1] # } n = 0 NoOf32bitChunks= 0 lstBitsBitwiseAnd = [] lstBitsModulo = [] lstViaBitChunks= [] lstBitsViaHex = [] lstBitsGMPY= [] lstViaHexAndArray = [] timeBitwiseAnd = -1 timeModulo = -1 timeBitsViaHex = -1 timeViaBitChunks = -1 timeGMPY = -1 timeViaHexAndArray = -1 bitChunkSize = 32 # must be = 32 while timeBitwiseAnd = timeBitsViaHex + 0.001: n = (n32) + 0x12345678 NoOf32bitChunks += 1 i = n lstBitsModulo = [] start = time.clock() while i: lstBitsModulo.append(i%2) i=i1 timeModulo = time.clock()-start i = n lstBitsBitwiseAnd = [] start = time.clock() while i: lstBitsBitwiseAnd.append(i0x01) i=i1 timeBitwiseAnd = time.clock()-start i = n lstViaBitChunks = [] bitFilter= 0 for dummy in range(bitChunkSize): bitFilter = (bitFilter1)+1 #:for start = time.clock() done = False while i: i1 = int(i bitFilter) # int() converts here a long-integer to integer i = bitChunkSize if i == 0: done = True for k in xrange(bitChunkSize): lstViaBitChunks.append(i1 1) i1 = 1 if done and i1==0: # if this is the top word, and no bits are left, we are done break #:if #:for #:while timeViaBitChunks = time.clock()-start i = n # lstBitsViaHex = [] start = time.clock() strHexOf_i = i.__hex__()[2:] if strHexOf_i[-1]=='L': strHexOf_i=strHexOf_i[0:-1] #:if intNoOfLeadingZeroBits = 0 lstBitsOfFirstNibble = dctLstOfBitsVsCharOfNibble[strHexOf_i[0]] while not lstBitsOfFirstNibble[intNoOfLeadingZeroBits] and intNoOfLeadingZeroBits 4: intNoOfLeadingZeroBits += 1 #:while if intNoOfLeadingZeroBits == 4: lstBitsViaHex = [] else: lstBitsViaHex = lstBitsOfFirstNibble[intNoOfLeadingZeroBits:] #:if for indxToStrHexOf_i in range(1,len(strHexOf_i)): lstBitsViaHex += dctLstOfBitsVsCharOfNibble[strHexOf_i[indxToStrHexOf_i]] #:for lstBitsViaHex.reverse() timeBitsViaHex = time.clock()-start i = n lstViaHexAndArray = [] import array, binascii start = time.clock() strHexOf_i = i.__hex__()[2:] if strHexOf_i[-1]=='L': strHexOf_i=strHexOf_i[0:-1] #:if for item in array.array('B', binascii.unhexlify(strHexOf_i)): lstViaHexAndArray += dctLstOfBitsVsOrdOfChar[item] #:for intNoOfLeadingZeroBits = 0
Re: Double Click Mouse Event in Tkinter
scott_gui wrote: Creating a Windows application: Double-Button-1 mouse event has a conflict when there is also a binding to the Button-1 event. It seems like a silly oversight that performing a double click will also initiate the single click action. If your design depends on your code being able to accurately figure out what the user will do in the future, you may want to go back to the drawing board. Has anyone figured out a way to circumvent this problem? Right now I am making the Double click function undo the action my Single click function does, but this is very annoying, especially since the action that is bound to the Single click flashes for a second. I don't think I've ever seen any recent application that does this (be- cause all possible solutions are annoying), but I seem to recall that the Explorer in some early version of Windows overloaded single and double click actions by delaying the single click action (click and wait = single click action, click and click = double click action). To implement this in Tkinter, you can schedule an after task in the Button-1 handler, and cancel it in the Double-Button-1 handler. But a redesign is probably a better idea... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python allow access to some of the implementation details?
Paul Rubin wrote: Claudio Grondi [EMAIL PROTECTED] writes: The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in computers memory? No it doesn't, and that's a good thing, since the internal representation is a little bit surprising (it stores 15 bits of the long int in each 16-bit word of the representation, to make the arithmetic routines a little simpler). Indeed. There are even more reasons why this is a Good Thing (tm) (not only because the internal representation is surprising). Basically it gives the implementor of a Python interpreter the freedom to choose the internal representation that he deems to be the most fitting. If implementation details leaked outside that wouldn't be possible anymore. Cheers, Carl Friedrich Bolz -- http://mail.python.org/mailman/listinfo/python-list
Re: Try Python update
Mike Meyer [EMAIL PROTECTED] wrote: And yes, I know about this. It's listed in Known Problems. Anything What's the URL to Known Problems? There's a strange cursor-placement bug on Apple's Safari browser (not in Firefox), but I don't want to add a bug report if you already know about it -- 'Try Python' is a neat hack, and useful, it well deserves some care from would-be bug reporters... but I can't see any links to known problems (or other bug-reporting facilities) from the base page. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code snippet?
LordLaraby [EMAIL PROTECTED] wrote: For what it's worth, GenerateRandomColour does not access any instance variables and therefore needn't even be a member of the class Population. If you wanted it there for encapsulation purposes, consider making it a staticmethod like so: @staticmethod() def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour No parentheses on the decorator line, just '@staticmethod'. Otherwise, fine. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy an Object (Again?)
KraftDiner [EMAIL PROTECTED] wrote: ... objs = myListOfObjects for obj in objs: if obj.flag: newObject = copy.deepcopy(obj) newObject.mirror() myListOfObjects.append(newObject) Never modify the very list you're looping on. I doubt this is the root of your problem, but, at any rate, loop on a COPY of the list you're modifying -- e.g. change the first statement to objs = list(myListOfObjects) Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Stackless Python
Xavier Morel wrote: Would anyone have more informations about that? It doesn't seem to be an issue on my side (since I tried to access the Stackless site from two different connections and 3 computers) but I can't rule it out. Thanks to Carl Friedrich, I restarted the Zope process. I have no idea why it broke, the site was running since 38 days without problems. The Zope/Plone process was still there, blocking the port. Maybe I should go for something simpler than Plone... Don't hesitate to ask on the mailing list for all the things you will not find on the site. The list works :-) ciao - chris -- Christian Tismer :^) mailto:[EMAIL PROTECTED] tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/ 14109 Berlin : PGP key - http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
Bryan Olson wrote: Words are important -- not only for what they mean, but for what the connotations they carry. For people who come to Python from C-like languages, the word reference means something that is just not true in the context of Python's behaviour. Wrong. C does not have references Unless they've changed it since the drafts, the ANSI C specification uses the word reference to describe how pointers work: A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type T is sometimes called ``pointer to T''. The construction of a pointer type from a referenced type is called ``pointer type derivation''. so unless you're using some odd dialect of C that doesn't support pointers, your C implementation sure has references. and the Python use is consistent with the rest of computer science. The problem isn't the word reference in itself, the problem is when people are implying that since Python passes object references to functions, it's using call by reference. In ordinary CS, call by reference generally means that the function is handed a reference to the *variable* holding the *value*. You can do this explicitly in C (by passing in arg instead of arg), and you can do this in C++, but there's no way to do this in Python -- Python variables hold objects, not values. Saying that Python uses call by value is probably more correct (where the values are references), but that's even more confusing. (see endless earlier threads for more on this). That would be a terrible thing to do. Just learn to use the meaning accepted in the discipline, and used in the Python doc. afaik, the Python Language Reference never defines the word reference. It carefully defines words like object and value, though, and terms like call by object or call by object reference are perfectly understandable if you use the words as they are defined in the language reference. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 'everything' a refrence or isn't it?
On Sat, 07 Jan 2006 01:29:46 -0500 Mike Meyer [EMAIL PROTECTED] wrote: From what I can tell, Liskov proposed *three* different names for passing references to objects: call-by-sharing, call-by-object, and call-by-object-reference. Call by object reference makes the most sense to me. Names in Python are object references: they refer to objects. You might almost say call by name but that sort of implies that you are passing the strings around (which is generally untrue), and it doesn't convey what happens when the name is something complex like ham['spam'][0].eggs()[42] (i.e. name carries the conotation of being a simple string, although you could argue that it doesn't have to mean that). -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list